You Are Here:

Community: Developer Discussion Boards

#1 Old creating new directory - 2009-07-04, 12:06

Join Date: Apr 2009
Posts: 35
jiten_shah18's Avatar
jiten_shah18
Offline
Registered User
import codecs
import os, os.path

path1 = u"C:\\Data\\MyApp\\temp.ini"

newline = "\n"

def init_settings():
f = codecs.open(path1, 'w', 'utf_8')
settings = "variable_1" + newline
settings += "variable_2" + newline
settings += "variable_3" + newline
f.write(settings)
f.close()



def mk_dir():
if not os.path.exists(path1):
os.makedirs(path1)



mk_dir()
init_settings()


problem: the directory along with file is getting created but there is no data inside,
emulator gives an IO error -Permission denied
Reply With Quote

#2 Old Re: creating new directory - 2009-07-04, 12:26

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
That's because you're creating the directory named temp.ini, and then trying to write to it as if it were a file. So call os.makedirs with the path C:\\Data\\MyApp, as C:\\Data\\MyApp\\temp.ini is the path of the file.

And please use the CODE tags when posting code (the button with the # symbol on it in the post editor). That keeps the code indented and easy to read.
Reply With Quote

#3 Old Thumbs up Re: creating new directory - 2009-07-04, 13:11

Join Date: Apr 2009
Posts: 35
jiten_shah18's Avatar
jiten_shah18
Offline
Registered User
thanx for ur help,it worked

can you tell me why it is creating only C:\MyApp folder instead of C:\Data\MyApp
Reply With Quote

#4 Old Re: creating new directory - 2009-07-04, 13:21

Join Date: Oct 2007
Posts: 2,841
Location: Deva, Romania
bogdan.galiceanu's Avatar
bogdan.galiceanu
Offline
Forum Nokia Champion
That's strange... If you use os.makedirs("C:\\Data\\MyApp") it should create the folder C:\Data\MyApp. That's what it did when I tried it.
Reply With Quote

#5 Old Re: creating new directory - 2009-07-04, 18:44

Join Date: Apr 2007
Posts: 131
mahesh.sayibabu's Avatar
mahesh.sayibabu
Offline
Regular Contributor
Quote:
Originally Posted by jiten_shah18 View Post
can you tell me why it is creating only C:\MyApp folder instead of C:\Data\MyApp
Are you sure that it has created C:\MyApp folder instead of C:\Data\MyApp ?
You can check using
Code:
import os
os.listdir('c:')
os.listdir('c:\\Data')
Some file browsers might show 'c:\Data' directly when you select phone memory. Hope this is one of such case.
Reply With Quote

#6 Old Re: creating new directory - 2009-07-08, 09:38

Join Date: Apr 2009
Posts: 35
jiten_shah18's Avatar
jiten_shah18
Offline
Registered User
hello mahesh.sayibabu,
yeah i am sure its creating c:\Myapp instead of c:\Data\Myapp
and even the code given by u has no output may i know what is the reason?
Reply With Quote

#7 Old Re: creating new directory - 2009-07-09, 05:50

Join Date: Apr 2007
Posts: 131
mahesh.sayibabu's Avatar
mahesh.sayibabu
Offline
Regular Contributor
Check with this code. It is tested on E71 with PyS60 1.9.6
The directory, file and the file contents are created as expected.

Code:
import codecs
import os, os.path

dir_path = u"C:\\Data\\MyApp"
file = "temp.ini"
newline = "\n"


def init_settings():
    f = codecs.open(os.path.join(dir_path, file), 'w', 'utf_8')
    settings = "variable_1" + newline
    settings += "variable_2" + newline
    settings += "variable_3" + newline
    f.write(settings)
    f.close()


def mk_dir():
    if not os.path.exists(dir_path):
        os.makedirs(dir_path)


mk_dir()
init_settings()
Reply With Quote
Reply « Previous Thread | Next Thread »
Display Modes
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules

You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump
Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot create sis package? gomcoite Themes/Carbide.ui 4 2008-09-27 18:54
Error in packaging process :( a-eqla3 Themes/Carbide.ui 2 2008-07-30 23:03
Error in packaging process :( a-eqla3 Carbide.c++ IDE and plug-ins 1 2008-07-24 21:33
ERROR IN CREATING THEME ssmantri Themes/Carbide.ui 5 2008-05-29 21:58
Creating a directory in a root directory ajitnair Mobile Java General 3 2007-11-07 16:48

Rate This

 
Bookmark this page: DeliciousDiggFacebookGoogleYahooStumbleUponRedditDiigoTechnocratiTwitter  Share this page Share this page Print this Page Print this page Invite a friend Invite a friend
京ICP备05048969号    Email Newsletters Press Terms & Conditions Privacy Policy Sitemap Contact Us © 2009 Nokia