![]() |
sub-folders in folders from text line - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: sub-folders in folders from text line (/thread-25454.html) |
sub-folders in folders from text line - jenost - Mar-31-2020 Hi! Tips on how to create sub-folders in each one created from an txt dokument. See code example. Should I also close the text file? import os with open('text.txt') as x: *creates folders named from textdokument* for line in x: line = line.strip() os.mkdir(line) *Here I want to create sub-folder in each folder*Tanks in advance! // Jens RE: sub-folders in folders from text line - ndc85430 - Mar-31-2020 I don't understand the question. You can use os.mkdir to create directories. There's also os.makedirs if you want to give a path and create all intermediate directories to the leaf (i.e. like mkdir -p on the command line would do).Also, no, you don't need to close the file - using with takes care of that for you (go and read about context managers if you're interested).
|