python - Creating folders based on a list read from a text file -
i have code follows:
from sys import argv import os; home_dir = '/home/joga' script, dirlist = argv mylist = open(dirlist, 'r') folder in mylist: newfolder = home_dir+'/'+folder print "folder name " +newfolder if not os.path.exists(newfolder): os.makedirs(str(newfolder)) os.chdir(newfolder) mylist.close()
the idea read list of folders listed in text file, , create each of these folders if don't exist. getting folders created, have strange names, example stray '?' appended folder name
how fix this?
answering own question
i added folder = folder.strip()
first line in loop. guess line-ending creating junk character.
Comments
Post a Comment