Renaming files in many sub-folders. Requirement: There is a huge directory list which has many sub-directories and one file in each sub-directory, which has to be renamed as sub-directory name with the original extension. Last sub-directory name is always 8 chars. After renaming is done, it has to be moved to a different folder. Wrote a small Python utility for this requirement.
✓ Published0🌍 Public
PP7h
Last edited May 14, 2014
Created on May 14, 2014
This example demonstrates a Python utility that renames a single file inside each sub-directory to match the sub-directory name while preserving the original extension, then moves it to a destination folder. It shows how `os.walk` traverses the directory tree, identifies the last 8 characters of each sub-directory name via string slicing, and uses `os.rename` to relocate and rename the file to `D:/GBR/`. The code relies on the standard `os` library for file system operations.
AI-generated description