I want to first read csv file then check if the folders exists, if not create a new one.
I have information from csv file as follows:
After reading csv file it should create program folder then under program folder it game type sub folder then developer sub folder and game char sub folder. The folder structure should look something like this:
- A380 / Warcraft / 69 / Blizzard / Strategy
- A380 / Overwatch/ 69 / Blizzard / Shooter
- A350 / Skyrim / 51 / Bethesda / Role Playing
output_root = r'/myProgram'
#csv_filename = raw_input('Enter CSV filename:')
with open('insurance_sample.csv') as csvfile:
readCSV = csv.reader(csvfile, delimiter = ';')
header = next(readCSV)
First you have to extract the values of one row and join them to a path name. Afterwards
os.path.exists checks if the directory exists and
os.makedirs creates recursively the directories for you.
So you can try this:
import os import csv with open('insurance_sample.csv') as csvfile: readCSV = csv.reader(csvfile, delimiter = ';') header = readCSV.next() for row in readCSV: dirname = "/".join((row, row, row, row, row)) if not os.path.exists(dirname): os.makedirs(dirname)