i have a .csv file such as the following:
name1,name2,name3 and so on
using Python script i am trying to have it read the .csv and make directories for each value
eg: name1,name2,name3 will create these directories :name1 and name2 and name3
this is my code so far:
import os
import fileinput
textFile = 'E:/Videos/Movies/subtest/dirlist.csv'
path = "E:/Videos/Movies/subtest/"
#generate a txt file with the current names of the directories
def makeFile():
# Open a file
dirs = os.listdir( path )
# This would print all the files and directories
for file in dirs:
#open the file
tFO = open(textFile, "ab+")
#write to the file, seprating each item with "||"
tFO.write( file + ',' )
#print output
print ( file )
#prints confirmation
print 'file printed!'
#close the file
tFO.close()
mainMenu()
def makeDirs():
#open textFile as read only and set its varible as myListRead
myListRead = open(textFile, 'rb+')
#reads the x amount of lines and stores it as str
str = myListRead.read();
for line in str:
os.makedirs(path + str)
print 'directories created:', str
running this code creates the .csv as i intended, but when i run makeDirs() it makes the directory name all of the .csv (name1,name2,name3 as the foldername)