Automating tasks in Python – Mass renaming of folders present in zip


ansh bansal

So Python is getting useful to me for avoiding manual repetitive tasks. I used it to rename a lot of folders. There were around 700 folders in 28 zip files which I needed to rename and re-zip. That would have been really cumbersome if not for Python.

The folders’ name were like  0001 – abc 1 . Only that the numbers didn’t match. The first number was used for arrangement and it was the second number according to which I had to change the first number. Doing that for 700 folders would have been a real pain. Luckily I knew Python and wrote a script for doing this.
Here’s the Python script that I used.

import zipfile import os import shutil CUR_DIR = os.getcwd() FILES_IN_CUR_DIR = os.listdir(CUR_DIR) def get_new_name(original_name): num = 0 started= False for c in original_name[7:]: if not c.isdigit(): if started is True: break continue else: started =…

View original post 147 more words