use regex to add new path

Post any Bulk Rename Utility support requirements here. Open to all registered users.

use regex to add new path

Postby slestak » Thu Jun 12, 2014 8:37 pm

I am wondering about this use case. I searched the forums and didn't see anything relevant.

I have a folder that contains x number of files. Each file has a special number as the first word, i.e. order number, doesnt matter.

I would like to copy these to a new location, where there is a folder with that order number that already exists.

The file does not need to be renamed, just moved to a folder identified by the first word. the filename doesn't change, just identify the folder to move it to by the first word.

An example would be:
Source
--------
c:\foo\123456 final.xls
c:\foo\123457 final.xls
c:\foo\123458,1234568 combined.xls

Destination
--------------
d:\bar\123456\123456 final.xls
d:\bar\123457\123457 final.xls
d:\bar\123458\123458,1234568 combined.xls
slestak
 
Posts: 2
Joined: Thu Jun 12, 2014 6:59 pm

Re: use regex to add new path

Postby truth » Thu Jun 12, 2014 11:23 pm

BRU will never create new DirPaths.
The closest you'll get is letting BRU create the commands that you need:

1Regex Settings:
^([0-9]+)([ ,])(.*\.xls)$
MD "D:\bar\\1" && COPY "\1\2\3" "D:\bar\\1\"
IncludeExt.=Checked

11Extension=Remove

This creates 'Newnames' as:
MD "D:\bar\123456" && COPY "123456 final.xls" "D:\bar\123456\"
MD "D:\bar\123457" && COPY "123457 final.xls" "D:\bar\123457\"
MD "D:\bar\123458" && COPY "123458,1234568 combined.xls" "D:\bar\123458\"

In the right-pane, you'd have to Right-Click / ClipBoardCopy / NewFileName + Ext.
Then paste the above commands into a batch, then run the batch from C:\foo

The commandline version, working along with sed/etc, is far better suited for this.
Since you could automate it simply by right-clicking a Dir to auto-copy your files.

Note the regex above only uses space or comma to denote EndOfDirname ([ ,])
Add more chars if needed, or use ([^\d]) to let 1st-non-digit denote EndofDirName
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay

Re: use regex to add new path

Postby slestak » Tue Jun 17, 2014 1:51 pm

Thanks for the input and info Truth.

A little more googling and I think this Powershell snippet is very close to what I needed.

http://superuser.com/questions/348956/powershell-get-inital-character-string-from-file-name-and-create-directory-from


Ive been leaning on BRU for a few years so I was investigating if I could use it for my current need. Anyway, ty!
slestak
 
Posts: 2
Joined: Thu Jun 12, 2014 6:59 pm

Re: use regex to add new path

Postby truth » Wed Jun 18, 2014 7:25 am

No worries, there's just no 1-step-solution to BRU not creating New DirPaths.

Sorry I'm unable to offer assistance with Powershell (downloaded/never-installed)
The script seems to determine MoveToPath by Leading9Chars, so definitely needs editing.
Theres alot of support for Powershell, so prob no-worries anyway.

If for some reason you need an alternative, here's a sed method:
dir/b *.xls|sed -n -r "s/^([0-9]+)([ ,])(.+)/MD \x22D:\\bar\\\1\x22 \& COPY \x22&\x22 \x22D:\\bar\\\1\x22/p"|sed e
Just change COPY to Move if desired, & input DirPaths with \\ to separate directories

-- OrigName ------ CopyToPath (names-unchanged)
123 final.xls -----> D:\bar\123\
123456,final.xls -> D:\bar\123456\
1234a, final.xls -> none (LeadingDigits must be terminated by either space/comma)
---------------------------- (Also, at least 1char must appear after the space/comma)
truth
 
Posts: 221
Joined: Tue Jun 25, 2013 3:39 am
Location: Earth, OrionArm, MilkyWay


Return to BRU Support