Another way to rename with text files (easy script!)
Hello friends,
You have a nice .csv file with current filename/new filename pairs, each on a line and separated with a comma. You don't remember how to use the import feature (I never do), and you're too lazy to look it up and study it (I always am). If you have Notepad++ or another text editor with regex replace, here's a fun and easy way to replace all those filenames with the new names. And you get to tell your buddies you just wrote some javascript. Probably get some dates with that line. :|
Here's my file, "test.csv":
this,that and the other
true,false or maybe
(one),another (one)
my,your
ours,theirs
It can be whatever, and you can have a different delimiter, but commas are pretty standard so that's what I'm using. If you want to follow along you can just first search and replace another delimiter with commas; otherwise change the search string. If your filenames have spaces in them don't enclose them in quotation marks; the replace will take care of that. If quote marks are already in the .csv just search/replace them out first.
The first word is the filename now, the second is what we want it to be. (If yours is the other way around just switch "$1" and "$2" in the replace string). After the search/replace each line will look something like this:
[for "this,that and the other" it will look like]: if (name=="this") name = "that or the other" ;
So once your .csv is in Notepad++ or whatever, do a regex replace like this:
Find what: ^(.+),(.+)
Replace with: if \(name=="$1"\) name="$2";
[no spaces in the find; no spaces on either *end* of the replace.
For some reason NP++ wants the parentheses escaped with the backslashes. My EditPad editor doesn't need them (but doesn't mind them either). Whatever, your lines should end up looking like the example I showed you above.
Now, on a blank line above the changed filename pairs, put this:
name = item.newBasename ;
And on a line below the filename pairs put this:
return name;
That's it. Copy all (Ctrl-A, Ctrl-C) and paste it (Ctrl-V) into a blank script method in ARen.
Press Ctrl-Enter to apply the script, add your files, check the new names, and you should be golden. Or at least dark yellowish. And if you are still reading this, you've probably made your first js script. :)
Screenshot: https://drive.google.com/file/d/11j9RWklj-ptWMesv9NHxhsvrm9e 1clvu/view?usp=sharing
EDIT: Not important here, but "name = name.replace( "this", "that or the other" ) ;" [without the outer quotes) will do exactly the same thing.
Best,
DF
You have a nice .csv file with current filename/new filename pairs, each on a line and separated with a comma. You don't remember how to use the import feature (I never do), and you're too lazy to look it up and study it (I always am). If you have Notepad++ or another text editor with regex replace, here's a fun and easy way to replace all those filenames with the new names. And you get to tell your buddies you just wrote some javascript. Probably get some dates with that line. :|
Here's my file, "test.csv":
this,that and the other
true,false or maybe
(one),another (one)
my,your
ours,theirs
It can be whatever, and you can have a different delimiter, but commas are pretty standard so that's what I'm using. If you want to follow along you can just first search and replace another delimiter with commas; otherwise change the search string. If your filenames have spaces in them don't enclose them in quotation marks; the replace will take care of that. If quote marks are already in the .csv just search/replace them out first.
The first word is the filename now, the second is what we want it to be. (If yours is the other way around just switch "$1" and "$2" in the replace string). After the search/replace each line will look something like this:
[for "this,that and the other" it will look like]: if (name=="this") name = "that or the other" ;
So once your .csv is in Notepad++ or whatever, do a regex replace like this:
Find what: ^(.+),(.+)
Replace with: if \(name=="$1"\) name="$2";
[no spaces in the find; no spaces on either *end* of the replace.
For some reason NP++ wants the parentheses escaped with the backslashes. My EditPad editor doesn't need them (but doesn't mind them either). Whatever, your lines should end up looking like the example I showed you above.
Now, on a blank line above the changed filename pairs, put this:
name = item.newBasename ;
And on a line below the filename pairs put this:
return name;
That's it. Copy all (Ctrl-A, Ctrl-C) and paste it (Ctrl-V) into a blank script method in ARen.
Press Ctrl-Enter to apply the script, add your files, check the new names, and you should be golden. Or at least dark yellowish. And if you are still reading this, you've probably made your first js script. :)
Screenshot: https://drive.google.com/file/d/11j9RWklj-ptWMesv9NHxhsvrm9e 1clvu/view?usp=sharing
EDIT: Not important here, but "name = name.replace( "this", "that or the other" ) ;" [without the outer quotes) will do exactly the same thing.
Best,
DF