[Tutor] creating directories
Lloyd Kvam
pythonTutor at venix.com
Wed Aug 4 01:32:48 CEST 2004
The os module has a function called makedirs which will make the
directories in a path. You can then use open to create the file.
os.makedirs('dir1/dir2/dir3', mode= <default is 0777>) # umask will also be applied
myfile = open('dir1/dir2/dir3/name.html', 'wt')
On Tue, 2004-08-03 at 18:48, Priyanka wrote:
> given a filename with the path, is there a possible way to create a new
> file with that name, simultaneously creating the directories in the
> file path.
> Suppose that I have to write to a file named:
> "dir1/dir2/dir3/name.html", where only dir1 exists, is it possible to
> create dir2 and dir3 and open a new file name.html to write on to.
>
> Thanks,
> ppareek
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
--
Lloyd Kvam
Venix Corp.
1 Court Street, Suite 378
Lebanon, NH 03766-1358
voice: 603-653-8139
fax: 801-459-9582
More information about the Tutor
mailing list