Move Files into Folders with Logic

Advanced Renamer forum
#1 : 13/05-22 16:16
Emily
Emily
Posts: 8
Hi, sorry that I don't know regular expressions, but I am looking to move files into one exisiting folder if they contain a certain text string and to another existing folder if they contain a different text string. Is this possible please? I have read the manual but I don't know how to do it without script.

E.g.
If file name contains 'firstfolder' move to Folder 1
If file name contains 'secondfolder' move to Folder 2

Thus
AB123_firstfolder.jpg to Folder 1
CD123_secondfolder.jpg to Folder 2
CD123_firstfolder.jpg to Folder 1

Folder 1 and Folder 2 are Subfolders of the base folder.

Thanks


13/05-22 16:16 - edited 13/05-22 16:26
#2 : 15/05-22 11:12
David Lee
David Lee
Posts: 1125
You will need to use a Script method to set item.newPath:

if (item.name.includes(dir = "firstfolder")) item.newPath = item.path + dir;
if (item.name.includes(dir = "secondfolder")) item.newPath = item.path + dir;




15/05-22 11:12
#3 : 17/05-22 12:46
Emily
Emily
Posts: 8
Reply to #2:

Thank you very much for your help. I'm sorry I'm a bit confused. Is this a rename script or a move batch script?

Also in the script do I need to change the top 'dir' after the '+' to 'First Folder' and the second 'dir' after the '+' to 'Second Folder'? The search string is slightly different to the folder name. In actual use, the folder names will be very different to search strings so I would like to specify them somewhere in each line.


17/05-22 12:46 - edited 17/05-22 12:50
#4 : 18/05-22 04:43
David Lee
David Lee
Posts: 1125
Reply to #3:
Just use a normal Rename batch. The script does not have a return statement so files are not renamed.

if (item.name.includes(dir = "firstfolder")) item.newPath = item.path + dir;

The variable "dir" is set in the if statement ie "(dir = "firstfolder")"
so change "firstfolder" to whatever it needs to be.

The statement is equivalent to:
if (item.name.includes("firstfolder")) item.newPath = item.path + "firstfolder";


18/05-22 04:43
#5 : 19/05-22 13:42
Emily
Emily
Posts: 8
Reply to #4:

Excellent, that worked well thank you very much. I may be able to manage with the script as is and rename all the folders afterwards, but what I was initially aiming for was more like:

if (item.name.includes("firstfolder")) item.newPath = item.path + "Blue Images";

Ie, I was hoping to be able get the renamer to attach 'y' if search string is 'x'



19/05-22 13:42
#6 : 19/05-22 17:42
David Lee
David Lee
Posts: 1125
Reply to #5:
If you want the file moved into a sub-folder named "Blue Images" then you have answered your own question!


19/05-22 17:42
#7 : 19/05-22 17:42
David Lee
David Lee
Posts: 1125


19/05-22 17:42 - edited 19/05-22 17:44
#8 : 19/05-22 17:42
David Lee
David Lee
Posts: 1125



19/05-22 17:42 - edited 19/05-22 17:43
#9 : 19/05-22 17:42
David Lee
David Lee
Posts: 1125


19/05-22 17:42 - edited 19/05-22 17:43
#10 : 20/05-22 17:57
Emily
Emily
Posts: 8
Reply to #6:
Oh, thank you! I had no idea it was as simple to make the revision as that! It works just as I envisaged now! Thanks for all your help.


20/05-22 17:57