Move files into the same folder when a word matches in its filename

Advanced Renamer forum
#1 : 06/02-23 20:42
Ervin
Ervin
Posts: 17
Is there a way to move files into the same folder when a word matches in its filename?


06/02-23 20:42
#2 : 07/02-23 08:48
David Lee
David Lee
Posts: 1125
This question does not make sense.

What do you mean by "same folder" and what is the "word" supposed to be matching?
Provide some examples.


07/02-23 08:48
#3 : 07/02-23 08:58
Theodore Evans
Theodore Evans
Posts: 1
This page has a lot of good weather information. I would tell everyone to do it





07/02-23 08:58 - edited 07/02-23 08:59
#4 : 08/02-23 10:59
Ervin
Ervin
Posts: 17




08/02-23 10:59 - edited 09/02-23 12:38
#5 : 08/02-23 10:59
Ervin
Ervin
Posts: 17
One way to group files into folders is when you use "Batch Mode: Move" you can use attributes in the "Output Folder" and it will move all the files into its matching folders.

For Example I group my files into video size:
<Video Width> X <Video Height>

That's pretty simple and straight forward... but is there way to group the files when a word or words matches in it's filename.

filename 1: Clip ABC - 123
filename 2: DEF Clip - 456

result: moved both files into a new folder "Clip" because both filenames have the word "Clip" in it.

I'm not sure its possible, but I thought you may have some ideas or suggestions.



08/02-23 10:59
#6 : 08/02-23 12:38
David Lee
David Lee
Posts: 1125
Reply to #5:
Use a Script method - works with any batch mode.

if (item.name.match(/\bClip\b/)) item.newPath = item.path + "Clip";

"\b" represents a "word boundary" so this will move any file with a name containing the separate word "Clip" into a sub-folder "Clip" situated in the same folder as the original file.

You can also set the path manually but be aware that the character "\" must be entered as "\\", otherwise it will have a special meaning.

eg:

myPath = "C:\\this\\is\\the\\new\\path\\";
if (item.name.match(/\bClip\b/)) item.newPath = myPath + "Clip";


08/02-23 12:38
#7 : 09/02-23 12:37
Ervin
Ervin
Posts: 17
Reply to #6:
Wow!.. I'll give it a try. I'm glad I asked. There is no way I could have figured that out. Thanks!


09/02-23 12:37
#8 : 09/02-23 13:32
Ervin
Ervin
Posts: 17
Reply to #6:
Thank you for the script...it works great with a "word boundary" but can it match automatically without stating a boundary, just based on two files having a matched word in its filename?.. maybe using a wildcard or something?


09/02-23 13:32
#9 : 10/02-23 16:25
David Lee
David Lee
Posts: 1125
Reply to #8:
"just based on two files having a matched word in its filename?" doesn't make sense - please explain further.

However if you just mean that you want to match the string "Clip" anywhere in the filename then simply leave out the word boundary characters.

In this case you don't need a regular expression, simply:

myPath = "C:\\this\\is\\the\\new\\path\\";
if (item.name.includes("Clip")) item.newPath = myPath + "Clip";

This doesn't seem to be what you are asking for though.


10/02-23 16:25