Getting the Directory/Path details
Kali K E
kalike2003 at netscape.net
Fri Sep 26 05:11:45 EDT 2003
More information about the Python-list mailing list
Fri Sep 26 05:11:45 EDT 2003
- Previous message (by thread): Getting the Directory/Path details
- Next message (by thread): Getting the Directory/Path details
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Peter Otten <__peter__ at web.de> wrote in message news:<bkv866$u2n$07$1 at news.t-online.com>... > Kali K E wrote: > > > Hi, > > I could not understand how I can do the following things in Python. > > Please help me. > > > > 1. First I have to find the current directory from where the script is > > invoked. > > 2. Next I have to form a directory structure there. If the current > > directory in step 1 is /home/mylogin, then from there I have to build > > a directory structure like > > /home/mylogin/result > > /home/mylogin/tmp/ > > /home/mylogin/..... > > > > There are three things as I look at it. First determing the current > > directory path. Second adding a string to it like /result etc. Third > > creating the new directory. > > Thank you for the help. > > > > Kali > > 1 os.getcwd() > 2 os.path.join() > 3 os.mkdir() or os.makedirs() > > <code> > import os > > subfolders = [ > "result", > "temp", > "something/else", > ] > > folder = os.getcwd() > > for sf in subfolders: > os.makedirs(os.path.join(folder, sf)) > </code> Hi, Thank you very much for the answer. It works fine when used first time. But when the directory already exists I am getting the following traceback message. Traceback (most recent call last): File "temp6.py", line 15, in ? os.makedirs(os.path.join(folder, sf)) File "/usr/lib/python2.2/os.py", line 203, in makedirs mkdir(name, mode) OSError: [Errno 17] File exists: '/hda1/home/kalike/chnages/python/result' How do I take care in such a case? Also can you please let me know where I can search for all these OS or system calls. Is it available as a document some where? Thanks, Kali
- Previous message (by thread): Getting the Directory/Path details
- Next message (by thread): Getting the Directory/Path details
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list