Hi,

I started Python command prompt and entered this:

import distutils.dir_util as du

du.mkpath( "c:/foo/bar" ) #assume dir 'foo' doesn't exist

This works fine and it creates the path 'foo/bar'.

Now, go to file explorer and delete the dir 'foo' and go to the Python prompt and issue the same cmd.

du.mkpath( "c:/foo/bar" )
Now, it just returns []

OTOH, if you try
du.mkpath( "c:/foo/bar2" )
it craps with an exception:

Traceback (most recent call last):
File "<pyshell#17>", line 1, in <module>
du.mkpath( "c:/foo/bar2")
File "C:\Python26\lib\distutils\dir_util.py", line 80, in mkpath
"could not create '%s': %s" % (head, exc[-1])
DistutilsFileError: could not create 'c:\foo\bar2': The system cannot find the path specified


Same thing happens on Linux too.
Any help appreciated - as to my incorrect usage or anything else.
Thanks

what are you trying to do? A folder creation?

os.makedirs('c:\\foo\\bar')

Look here.
Cheers and Happy coding

I recommend Shutil module for file operations. You can even make class to deal with all basic file operations

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.