Click here to Skip to main content
15,892,161 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a 'Movie' folder. Inside of this folder, there are several different movie subfolders with the video file and subtitle file. Eg. Avengers, bad boys, ocean 11, etc. These subfolders with movie names contain video files along with subtitle files. I wish to rename the subtitle files as same as the movie folder's name. Eg, if my subtitle file is in the folder named 'MOVIEx' then I want my subtitle file's name to be changed as 'MOVIEx'. I don't know how to give multiple path locations in the second argument of .rename() as this function only accepts one dest path, whilst I have several paths with different subtitle file names.

What I have tried:

# to walk through all the folders and subfolders in directory 'Movies'.
for foldername,subfoldername,filename in os.walk(r'E:\Movies'):
    # to check for the subtitle file.
    if filename.endswith('(.srt|.idx|.sub)'):
        # change the subtitle file name with movie subfolder name.
        os.rename()
Posted
Updated 29-Aug-20 7:09am

AFAIK, you don't. You rename each file, one at a time.
 
Share this answer
 
Quote:
How to give multiple path names as second argument in rename() to rename the files.

Short answer: You don't.
- You need to recursively scan the tree of directories.
- for each file you want to rename.
- you butcher the file path to extract the actual subdirectory name.
- you assemble the new file name from parts you have.
- and then you do the rename.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900