#1 01 Feb 2021 22:13

Rekrul
Member
Registered: 17 Apr 2016
Posts: 93

How to keep track of two separate file lists at the same time?

Sometimes I rename files I've downloaded to have them make more sense to me, but then at a later date I need to rename them back to their original names. Currently I make a script to do this using macros in my text editor. I'd like to make a script to automate the process.

How I imagined it would work: Run the script and it reads the original filenames and outputs them all to a file, then pauses. I rename the files, then hit a key to let the next part of the script run and it reads the new filenames, pairs them with the original names in the file and uses ECHO to output both names to a batch file along with the REN command, like this;

echo ren "NewName.ext" "OldName.ext" >Rename.bat

However, the only way I know to read the contents of a file, or the names of files in the directory is with a FOR loop and as far as I know, FOR loops can't run concurrently. You can nest them, but the second loop will always run to completion on each repetition of the parent loop.

The only solution I came up with was using a counter to keep track of which name is being read from the file and grab the required one. In other word, when reading the 5th new filename, let the FOR loop read through the list of old filenames and copy the 5th one to a variable.

I was wondering if there was an easier way to do it?

Offline

Board footer

Powered by FluxBB