Files to own folders - named by the part* of filename

Hi, I'm trying to move files to folders by the first part of the filename.

I have some files with different names, but with Dates that are always in the same format eg 01.mon.year

BLAH.BLAH.BLAH.03.SEP.2002.txt
BLAH_BLAH_04_DEC_2002_blah_blah.txt

-I want to move them to folders named after the first part of the filename (everything before the date).
-Remove the dots and underscores in the foldernames.
-Files should not be renamed.

eg.
BLAH.BLAH.BLAH.03.SEP.2002.txt
= BLAH BLAH BLAH\BLAH.BLAH.BLAH.BLAH.03.SEP.2002.txt

or

BLAH_BLAH_04_DEC_2002_blah_blah.txt
= BLAH BLAH\BLAH_BLAH_04_DEC_2002_blah_blah.txt

This is what I have done so far, which works, but only on 1 file at a time (trying to do multiple selected returns the error " can not create file when exists ")

RENAME REGEXP PATTERN = "(.*)([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\{file}" TYPE=files 

This one removes the dots in the folder name:

@set filename={file} Rename PATTERN="." TO=" " FINDREP RENAME REGEXP PATTERN = "(.*)([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\{$filename}" TYPE=files

Can I make it work on all selected files? Or won't it work?

Add "AUTORENAME" to your first Button to make it working on all selected files.

This works for the first part.

RENAME REGEXP PATTERN = "(.*)([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files

I've been trying to write something that does both renames in one RegExp, but I don't have it quite working yet.
If I get it working, I'll post it.

Well this almost works, but it doesn't work as I'm repeating the pattern.

RENAME REGEXP PATTERN = "([^\._]*)[\._]([^0-9]*)(.*)#" TO="\1 \2\\\0" TYPE=files

If the move to the new folder is eliminated, it does work though.

RENAME REGEXP PATTERN = "([^\._]*)[\._]([^0-9]*)(.*)#" TO="\1 \2" TYPE=files

There might be a better way to remove the dots and underscores from the foldernames but if you don't care to remove them from all folders in the current directory this one is working for me:

RENAME REGEXP PATTERN = "(.*)([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files Select ALL TYPE=dirs /home\dopusrt.exe /cmd Rename PATTERN="_" TO=" " FINDREP /home\dopusrt.exe /cmd Rename PATTERN="." TO=" " FINDREP

Thanks for the help, this works much better. Still trying to get the first part going before I attempt the folder, since I came across odd issue I can't work out.

RENAME REGEXP PATTERN = "(.*)([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files

If there's a space present before the first digit it won't work: TEST 03.DEC.2002.txt

Putting a space in before the first number match will fix that, but then it stops working on files that don't have a space.

RENAME REGEXP PATTERN = "(.*) ([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files

I tried repeating the line, one with / one without a space but it pulls errors, though it works.

I thought that (.*) would have matched 0 or more of any character (including a space). It kind of does, but not 0 or more characters ending in a space.

How could I say 0 or more characters possibly ending in a space? So it will work on both these files:

TEST.03.Dec.2002.txt TEST 03.Dec.2002.txt

RENAME REGEXP PATTERN = "(.*[^ ])( ?[0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files

The ? operator acts on the space character 0 or 1 time.
At the same time the last character of /1 cannot be a space.

For part of your RegEx find criteria, you could use something like

([^0-9]*)

which will find anything including a space up until the first digit. However then in your rename to part you're likely going to run into a snag if Opus tries to create a new subfolder whose name ends in a space as ending spaces are not allowed in folder names.

Using your original regular expression, this perhaps is a little better.

RENAME REGEXP PATTERN = "(.*[^ \._])[ \._]?([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files

This eliminates the '_' , '.' ( not really needed ), as well as the ' ' at the end of the folder names

Oh so it was the space on the end of the folders that was the issue, would never have guessed.

[quote="Scred"]Using your original regular expression, this perhaps is a little better.

RENAME REGEXP PATTERN = "(.*[^ \._])[ \._]?([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files

This eliminates the '_' , '.' ( not really needed ), as well as the ' ' at the end of the folder names[/quote]

Thanks so, so much Scred for all those modifications. Both the last 2 work perfect with the space issue. Love this new button, it's so efficient, and going to save so much time.

[quote="kundal"]There might be a better way to remove the dots and underscores from the foldernames but if you don't care to remove them from all folders in the current directory this one is working for me:

RENAME REGEXP PATTERN = "(.*)([0-9])([0-9])(.*)([0-9])([0-9])([0-9])([0-9])(.*)" TO="\1\\\0" TYPE=files Select ALL TYPE=dirs /home\dopusrt.exe /cmd Rename PATTERN="_" TO=" " FINDREP /home\dopusrt.exe /cmd Rename PATTERN="." TO=" " FINDREP[/quote]

Yep, thanks this is the way to go for removing dots n dashes from folders, don't need them in any folder names. My original method was a bit messy.

Thanks everyone for all the help, very much appreciated.

Silly note: but if you're running the sort of commands shown directly above from an Opus button/hotkey/etc... I don't believe there's any need to prefix dopusrt with /home and include the executable exe extension. You should be able to use just dopusrt /cmd instead of /home\dopusrt.exe /cmd...