Sounds simple enough, right? I thought it was too until I had to put a couple of things I’ve learnt together for the program to work.
I was working on ‘Selective Copy’ in Chapter 9 of ‘Automate the Boring Stuff with Python’.
Write a program that walks through a folder tree and searches for files with a certain file extension (such as .pdf or .jpg). Copy these files from whatever location they are in to a new folder.
I decided to only work with .pdf and over-complicated it by using regex to search for files with .pdf extension when it was as simple as using filename.endswith(.pdf):
I then kept getting errors:
I was quite annoyed as it took me awhile before realising that I needed all the files to be in the same directory for the program to work; such a fundamental mistake. Then again, these silly mistakes are inevitable for beginners and I believe there will be more of such mistakes in months to come as part of the learning phase.
Keeping my head up!