×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Apr 2009
    Posts
    36

    creating new directory

    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

  2. #2
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: creating new directory

    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.

  3. #3
    Registered User
    Join Date
    Apr 2009
    Posts
    36

    Thumbs up Re: creating new directory

    thanx for ur help,it worked

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

  4. #4
    Super Contributor
    Join Date
    Oct 2007
    Location
    Deva, Romania
    Posts
    3,471

    Re: creating new directory

    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.

  5. #5
    Nokia Developer Expert
    Join Date
    Apr 2007
    Posts
    131

    Re: creating new directory

    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.

  6. #6
    Registered User
    Join Date
    Apr 2009
    Posts
    36

    Re: creating new directory

    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?

  7. #7
    Nokia Developer Expert
    Join Date
    Apr 2007
    Posts
    131

    Re: creating new directory

    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()

Similar Threads

  1. Error in packaging process :(
    By a-eqla3 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2008-07-24, 20:33
  2. Creating a directory in a root directory
    By ajitnair in forum Mobile Java General
    Replies: 3
    Last Post: 2007-11-07, 15:48

Posting Permissions

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