VideoHelp Forum
+ Reply to Thread
Results 1 to 4 of 4
Thread
  1. I have my rename code just stuck in a problem
    After renaming the file 01.srt to title_movies_01.srt
    How is it possible to save a file on above it of it so that it saves a file inside the folder


    "names.txt" inside file text
    Code:
    title_movies_01.srt

    "subtitle_output" inside folder
    Code:
    01.srt

    after renaming
    subtitle_output/title_movies_01.srt

    Code:
    import glob
    import os
    
    path_to_images = glob.glob(r"subtitle_output/01.srt")
    
    with open('names.txt') as f:
        for line, file in zip(f, path_to_images):
            os.rename(file, line.strip())
    Code works but does not save a file in the same folder subtitle_output
    Last edited by D.LUFFY; 4th Jun 2023 at 09:02. Reason: code change
    Quote Quote  
  2. I found a solution. Close
    Quote Quote  
  3. Then why don't you share the solution? It may help someone else in the future.
    Quote Quote  
  4. Code:
    import os
    
    f = open('names.txt', 'r')
    name = f.read().strip("\n")
    f.close()
    f = open("path/01.srt", 'r')
    text = f.read()
    f.close()
    
    os.remove('path/01.srt')
    
    f = open(f"path/{name}", "w")
    f.write(text)
    f.close()
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!