Automated file management in Python.

Brendan Ferris
3 min readMay 30, 2021

I recently was involved in a project that involved the creation of an automated tool that collects a large amount of documents. In order to save these documents, it was necessary to make create files and folders on the local filesystem where the rest of the script could access the information. In this article I’m going to walk through some of the basics of file management in python using mostly the os module and the shutil module, which is part of python’s standard library (you don’t need to download anything).

The first issue I came across was how would we name the files? I our case, they were PDF’s but the names sometimes contained spaces and special characters. I decided that in order to retain the information it would be a good idea to convert the original filenames into Base64, then rename the files with the Base64 string. This way, if we ever needed to see the original file name all we had to do was decode the Base64 string. No information loss!

The following methods can be used to achieve this result:

--

--