Auto move grouped files into own folders

Hello,

Not sure how to name this topic, you can rename if needed. If I have these files:

tripday01_001.jpg
tripday01_002.jpg
tripday02_001.jpg
tripday02_001.jpg

Can I get a button that would auto move the sets to their own folders, named after the file name up to the separator (the separator can be "_" or "-")? Example:

tripday01/
tripday01_001.jpg
tripday01_002.jpg
tripday02/
tripday02_001.jpg
tripday02_002.jpg

Thanks

Rename REGEXP PATTERN "([^_-]+)((_|-).+)" TO "\1/\1\2"

b[/b] is any character (at least one) but _ or -
b[/b] is _ or - followed by at least one any character

Thanks kakartha!

Works perfectly! And thanks for the explanation.

I just added Select ALLFILES to save a click :slight_smile:

Thanks again :thumbsup:

Sorry, I just don't understand regex enough to modify this button. If someone could help, that would be great!

How can I do the same thing as above, but this time, move files to a folder named after whats between 2 sets of "_" or "-" ?

Example:

tripday_01_001.jpg
tripday_01_002.jpg
tripday_02_001.jpg
tripday_02_002.jpg

TO

01/
tripday_01_001.jpg
tripday_01_002.jpg
02/
tripday_02_001.jpg
tripday_02_002.jpg

Rename REGEXP PATTERN "(.+[-])(.+)([-].+)" TO "\2\\1\2\3"

That's fantastic! Thank you MrC!

Yes, I tried for days to get this myself. I just don't understand regex or coding, sorry.

How could I move everything all into the same folder, up to the first number?

tripday01_001.jpg
tripday10_001.jpg
LasVegas001.jpg
LasVegas002.jpg

TO

tripday/
tripday01_001.jpg
tripday10_001.jpg

LasVegas/
LasVegas001.jpg
LasVegas002.jpg

Thanks!

You'll get the hang of it. Practice small pieces.

Old name: (\D+)(\d+.*)
New name: \1\\1\2

I really am trying to learn this. Reading online samples/tutorials, looking at other buttons, etc. I'm sure I'll be back for more help someday :\

I found Regex Coach. I think it'll help a lot. It can tell me whats getting selected and where the splits are :slight_smile:


Thanks again MrC!

I'm back :smiley:

I'm trying to do the same as above but this time by grabbing X amount of characters from the beginning and making that the folder. Example, this works for grabbing the first 4 characters:

Rename REGEXP PATTERN "(.{4})(.+)" TO "\1/\1\2"

Instead of making buttons for "3", "4", "5" etc characters, I'm trying to set the character count value to a variable:

@set count={dlgstring|Enter the number of characters to use} Rename REGEXP PATTERN "(.{{$count}})(.+)" TO "\1/\1\2"

But it just doesn't seem to work. It moves only 1 file (with the wrong name), then pops-up the rename dialog box to rename the others (since the same name already exists). Plus it moves it to a weird named folder that's up one root level. Any help would be appreciated!

While I'm asking (I'd rather have this button instead). Is it at all possible to first ask which character spot to start from? Then ask how many characters to grab? That why, I can start grabbing from character 5 and go 3 characters. Example:

tripday01_001.jpg
tripday01_002.jpg

Would move the above files into a "day" folder.

If there is a ton of coding that needs to be done, then never mind. I'll just make separate buttons then :slight_smile:

Thanks for any help!

It seems the {{$count}} requires escaping the first { and last }, but I don't know what the escape character is for this. I've searched the docs, but can't find it, nor how to concatenate strings into a single string.

Thanks again for your time MrC.

You're welcome. Maybe jon or leo will have an answer re: the required quoting mechanism.

I'd use a rename script instead:

Rename TO "{dlgstring|Enter the number of characters to use}" @script vbscript option explicit Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName ) Dim intChars intChars = CInt(strNewName) if (intChars < 1) then strNewName = strFileName ' Do nothing else strNewName = Left(strFileName,intChars) & "\" & strFileName end if End Function

Or this one, which also makes sure it doesn't take characters out of the file extension, if the number you give is greater than or equal to the length of the main part of the filename:

Rename TO "{dlgstring|Enter the number of characters to use}" @script vbscript option explicit Function Rename_GetNewName ( strFileName, strFullPath, fIsFolder, strOldName, ByRef strNewName ) Dim intChars Dim intExtensionPos intChars = CInt(strNewName) intExtensionPos = InStr(strFileName, ".") if fIsFolder or 0 = InStr(strFileName,".") then intExtensionPos = Len(strFileName) + 1 end if if (intChars < 1 OR intChars >= intExtensionPos) then strNewName = strFileName ' Do nothing else strNewName = Left(strFileName,intChars) & "\" & strFileName end if End Function

Works perfectly! (of course)

Thank you for your time and expertise Leo! And again to MrC, for my other buttons. I now have a nice little collection to handle just about any scenario that I might have (at least what I've seen so far). These buttons are saving me a ton of clicks and hours of time. Thank you! :thumbsup: :opussanta:

Leo - is it correct that it is not possible to embed a {$xyz} control code inside curly braces (i.e. no escape char within a string)? I can see this would have some utility.

I'm not sure :slight_smile:

Consider it a holiday challenge. :slight_smile:

Happy Holidays to the DOpus crew.

Leo came up with a nice workaround for now: