[Tutor] OS lib creating an directory using an absolute path.
Ming
ming at pgp.cool
Sat Feb 6 05:50:33 EST 2021
On Sat, Feb 06, 2021 at 09:33:26PM +1100, mhysnm1964 at gmail.com wrote:
> All,
>
> I am using the os library. If I have a directory structure with any missing
> directory (folders), then the os.mkdir function fails as it cannot find the
> filenamefilename. For example:
>
> Current directory structure is:
>
> C:\books with nothing inside.
>
> The path I am wanting to create is:
>
> E:\books\a\anne rice
>
> Yes, I could break the path and check each level of the directory. But I was
> wondering if there was any other method to do this. As if you do this at
> Windows 10 command line:
>
> Mkdir E:\books\"a\anne rice"
>
> The 'a' directory plus 'anne rice' is also created.
>
> I hope this makes sense. Python 3.8 under windows 10.
>
> Sean
>
Hello, I think you may need to use os.makedirs instead of os.mkdir.
It will recursively create directories, and if the path parameter has
only one level, it is the same as the mkdir() function.
--
OpenPGP fingerprint: 3C47 5977 4819 267E DD64 C7E4 6332 5675 A739 C74E
More information about the Tutor
mailing list