Use Python to Add References to Audit Workpapers
Use Python to Add References to Audit Workpapers

Use Python to Add References to Audit Workpapers


Sometimes as an auditor, we will get a lot of documents. It helps to organize the workpapers by numbering them so they can be referenced more easily. If we get a lot of documents, it can be a time-consuming task to rename those documents. 

In this training, we will show how to rename all documents in a folder with a numbered prefix WP01, WP02, and WP03.



To get the jupyter notebook and example files used to perform this process visit my website to download it.

If you want to watch how I renamed the files you can see that here



We want to add a prefix that will start with WP and then numerically increment by 1 through all files in the "Rename_Files" folder.

No alt text provided for this image

We will create a Jupyter Notebook in the folder outside the Rename_Files folder.

We will call it Detailed Rename Workpapers

No alt text provided for this image

We will import some operating system functions and libraries. We will then get our current location. We will then add the name of the subfolder we want to work on and we will add it to our current location and save the whole path together.

No alt text provided for this image

We will create a list called file_list. We will loop through all the files in our directory. We also use .isfile to determine if the file is a file because I don’t want to rename folders just files. I then add these items to the list file_list.

No alt text provided for this image

We will then loop through each file and we will use .index to get the position of the file. 

No alt text provided for this image

Now Python starts to count with zero and I would prefer my workpapers to start with a 1 so I will add 1 to the position so it starts on 1.

No alt text provided for this image

Additionally, I like to have my workpapers be forced to have two digits 01, 02, 03… 10 so that when you sort the names it sorts correctly. So we will use .zfill(2) which will force it to have two digits. You can change it to 3 if you want it to have 3 digits.

No alt text provided for this image

Lastly, we will use the os.rename function to rename our files. It takes two items. The first item is the original file name. Then after the comma, you will put what you want the file to be. So we take our file path then we need to put two backslashes to denote we want it inside the rename folder. “i” will be the file name.

The for loop will loop through all the files in file_list.

No alt text provided for this image

We now have our workpapers renamed

No alt text provided for this image

I do include a detailed version and a summarized version in my sample programs. You can run either of them and it will rename files. The detailed version has each step broken out like my tutorial here. The summarized version just has two main blocks of code which will define the files to rename and then rename them.

To view or add a comment, sign in

Others also viewed

Explore content categories