I am creating a script to create new folder hierarchies for a friend of mine. There are around a thousand clients, so a script would save a ton of time. I have everything almost working, the part I don’t have is this.
yearList = os.listdir(driveLetter + clientName)
for year in yearList:
os.chdir(year)
os.mkdir('Folder One')
os.mkdir('Folder Two')
os.mkdir('Folder Three')
Under this, are creations for sub folders, like so:
# Create folders under 'Folder One'
os.chdir(driveLetter + clientName + '\\' + year + '\Folder One')
os.mkdir('Sub Folder One')
os.mkdir('Sub Folder Two')
2005 is the first element in the list of yearList. This runs fine for 2005, but I get this error:
WindowsError: [Error 2] The system cannot find the file specified: '2006'
This would really help my friend out, so I am pretty motivated to do it (And pretty[read: very] new to programming)
Thanks for any assistance that can be provided
In the
for year in yearListloop you change to the year’s subdirectory, but probably never leave it again. So in the first iteration you enter the “2005” subdirectory and in the second iteration you are still in that subdirectory. Then you get the error that there is no “2006” directory (in the current “2005” directory).You can work around that by leaving the subdirectory again at the end of the loop: