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.

what are you trying to do? A folder creation?


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