-1

Ok, this is weird and maybe awkward. I made a script so I could change the end of subtitles files to keep consistency. Basically it replaces A.X.str to A.Y.str. It worked flawlessly at a single folder.

I decided then to make a recursive version of it so I could do it on any folder I had, regardless if the episodes where together, separated by season or each on an individual path.

I really don't know how or why, but it sent all the files it reached to the root folder I was using until it halted raising a FileExistsError.

The code bit I'm using is:

def rewrite(folder, old, new):
    for f in next(os.walk(folder))[2]:
        os.rename(os.path.join(folder, f),
                  os.path.join(path, f.replace(old, new)))
    for f in next(os.walk(folder))[1]:
        x = os.path.join(folder, f)
        rewrite(x, old, new)

Where 'old' is "A.X.str", 'new' is "A.Y.str" and folder is the full path of the root folder "C:\Series\Serie Name".

Why doesn't this work as recursive? The first bit of code (First FOR loop) works fine on it's own in a single folder. Is the problem with the "next" I use to get the names of files and folders?

0

1 Answer 1

2

The code you are showing us is using a path variable in the rename destination -- that should be the folder variable instead.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.