i am trying to create bulk folders based on simple text file. os.makedir helps to create new folder but i am not sure how to incorporate with newpath variable along with folder list. following is what i am trying with. I understand that code has syntax error. So need some help to correct/enhance the code.
import os.path
newpath = r'C:\Program Files\test\'
with open('folders.txt') as f:
for line in f:
ff = os.makedirs(newpath,line.strip())
ff.close()
Perhaps something like this?
Notes:
os.path.join()to combine a paths. This will automatically use separators that are suitable for your OS.os.makedirs()does not return anythingos.makedirs()will raise anOSErrorexception if the directory already exists or cannot be created.