PDA

View Full Version : Python - Search for and create directory


ironfistchamp
November 18th, 2006, 03:06 PM
Hey all


Can Python search along a path (given to it via a string) and see if a directory is there. If it can, can I then create a directory?

Any answers would be really helpful

Thanks

Ironfistchamp

po0f
November 18th, 2006, 07:01 PM
ironfistchamp,

Try os.walk() or os.path.walk(), one of those is bound to be what you are looking for.

ironfistchamp
November 19th, 2006, 09:29 AM
Thank you I shall look them up.

xtacocorex
November 19th, 2006, 10:07 AM
In my Autokernel code, we check to see if /tmp/autokernel is there and if not, we create it. Here is the code for that:

# Create '/tmp/autokernel' if it does not exist.
if not os.access('/tmp/autokernel', os.F_OK):
os.mkdir('/tmp/autokernel')

Hopefully this helps some also.

dwblas
November 20th, 2006, 12:24 PM
Similiar to above:
import os
def Check_Create_Dir( full_path_name ) :
if not os.path.isdir(full_path_name)
os.mkdir( full_path_name )