Getting the Directory/Path details

Peter Otten __peter__ at web.de
Thu Sep 25 13:19:55 EDT 2003


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>




More information about the Python-list mailing list