#1 2006-09-26 18:43

dexus
Member
Registered: 2006-09-26
Posts: 3

Make folder name from first (n) digits, and move files into folders

This function is something I found in "The Rename" another app.. and it's the one thing I miss from ReName.  I often download files from cameras and the web where files belonging in the same album and/or folder have a common prefix.  My goal is to easily move all the files with the same prefix into a new folder named after that prefix.

example:

I have files named:

PCX1-01 - holiday.ext
PCX1-02 - Beach.ext
PCX3-01 - Car at home.ext
PCX1-02 - Funny.ext
PCX2-01 - Work.ext
PCX2-02 - Family.ext
MCX14-14 - Neighbours.ext
and so on..

Now I would like to move all the files named PCX1* into a folder called PCX1, all the files named PCX2* into a folder named PCX2 and so on..
That would mean a rule where i can specify the number of digits in the prefix it should name the folder from and then ask if i want to move the files into their respecitve folders after creating the folder.

Does this make any sense?  It sure would make my day easier.. Even tho it's not hard to make the folders by hand, it takes alot of time when you process 1000+ files in series of 10...

Thanks for reading!

Dexus.

Offline

#2 2006-09-26 22:31

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Make folder name from first (n) digits, and move files into folders

Hi dexus smile

It is possible.. By inserting a "\" (slash) character to wherever you want - ReNamer would automatically create relative folders and move files into them. But what you want to do is a bit more complex, and you have to use or RegEx rule or PascalScript.

Using RegEx...
Expression: ([\w]*)-(.*)
Replace: $1\\$0

Preview will look like on the image below:

renamerfoldersfromnameszc7.gif

Will that do your job?

Offline

#3 2006-09-27 01:51

dexus
Member
Registered: 2006-09-26
Posts: 3

Re: Make folder name from first (n) digits, and move files into folders

Ah.. I see.. or at least I'm getting there.. RegEx have never been my strongsuite.. That's why I was after an easier way to do this..

Let me see if I got this correctly:

([\w]*)-(.*) is breaking up the filenames to everything before the first "-" and the rest...

The replace function then makes a folder out of the first part, and places the whole file into this folder...

But, alas.. what if I had a situasion where the files didn't have a common character to split the folder name and the rest of the file...

example:

PCX100-10 Filename1.ext
PCX120 20 - Filename2.ext
PCX130.Filename3 50-10.ext
PCX100_40-Filename4.ext
and so on..

I still would like to make folders of the first 6 characters of the filename and still place the respective file in that folder...
I'm sorry to bother you with this, as I'm sure that this also can be done with regular expressions.. Anyone know a crash course in regex?

Thanks for the quick reply :-)

Dexus.

Offline

#4 2006-09-27 11:06

den4b
Administrator
From: den4b.com
Registered: 2006-04-06
Posts: 3,374

Re: Make folder name from first (n) digits, and move files into folders

Yep, you got it right, breaking up the pattern!

Here is the pattern for the second example:
Expression: (.{6})(.*)
Replace: $1\\$0

And as you probably guessed {6} specifies amount of characters, while "." means any character and ".*" means any number of any characters. Roundy brackets group things, so they could be later accessed via $1, $2, $3, and so on... while $0 will represent the whole string. "\" is an escape symbol, so it has to be escaped by it-self. Here is a good place for you to start: http://www.regular-expressions.info/. And there is a help for RegEx within ReNamer, find the help icon within RegEx rule.

Here is screenshot of the pattern above in use:
renamerfolderfrom6charswr7.png

Offline

#5 2006-09-28 06:06

dexus
Member
Registered: 2006-09-26
Posts: 3

Re: Make folder name from first (n) digits, and move files into folders

That's great! Thanks alot..

And thanks for the link to regular exp. help.. I will study it for sure.

Dexus.

Offline

#6 2010-03-25 18:39

tenoko74
Member
Registered: 2009-05-17
Posts: 2

Re: Make folder name from first (n) digits, and move files into folders

Hello again

I read this post and was happy to find a answer to my problem, but it a two step process.

Example:
I have files like so:

name1 c000.ext
name1 c001.ext
name2 v00 c000.ext
name2 a c001.ext
name3 v00.ext

I tried: 
Expression:  ([\w].*) v(.*)
Replace:  $1\\$0
Results:  x:\folder\name2\name2 v00 c000.ext
               x:\folder\name3\name3 v00.ext

and

Expression:  ([\w].*) c(.*)
Replace:  $1\\$0
Results:  x:\folder\name1\name1 c000.ext
               x:\folder\name1\name1 c001.ext
               x:\folder\name2 a\name2 a c000.ext

these work the way I want to, but I was looking for a way to do it all at once.
Example:
x:\folder\name1\name1 c000.ext
x:\folder\name1\name1 c001.ext
x:\folder\name2\name2 v00 c000.ext
x:\folder\name2\name2 a c001.ext
x:\folder\name3\name3 v00.ext

Offline

#7 2010-03-25 20:58

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Make folder name from first (n) digits, and move files into folders

tenoko74 wrote:

Expression:  ([\w].*) v(.*)
Replace:  $1\\$0
and
Expression:  ([\w].*) c(.*)
Replace:  $1\\$0

these work the way I want to, but I was looking for a way to do it all at once.

Quick shoot, un-tested:

Look into an RegEx manual,
as here for example into our wiki => http://www.den4b.com/wiki/ReNamer:Regul … ternatives

and try  Alternatives like:
Expression:  ([\w].*) c|v.*
Replace:  $1\\$0

But...
since "c.*" or "v.*" could perhaps match to "Name1" too,
better try something like
Expression:  ([\w].*) c|v00.*
Replace:  $1\\$0
to match c|v followed by two zero digits '0'

or
Expression:  ([\w].*) c|v\d{2,}.*
Replace:  $1\\$0
to match c|v followed by at least two, or more of any digits '0', '1', '2', '3'...

HTH?  smile


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

#8 2010-03-26 08:26

SafetyCar
Senior Member
Registered: 2008-04-28
Posts: 446
Website

Re: Make folder name from first (n) digits, and move files into folders

Maybe some one could explain the behavior of the $0 on the wiki? I don't know what it is exactly but looks interesting roll

It returns the full match even if it's not between brackets isn't it?


If this software has helped you, consider getting your pro version. :)

Offline

#9 2010-03-26 10:42

narayan
Senior Member
Registered: 2009-02-08
Posts: 470

Re: Make folder name from first (n) digits, and move files into folders

See here:
http://www.den4b.com/wiki/ReNamer:Rules:Rearrange

Last edited by narayan (2010-03-26 10:43)

Offline

#10 2010-03-26 11:33

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Make folder name from first (n) digits, and move files into folders

SafetyCar wrote:

Maybe some one could explain the behavior of the $0 on the wiki? I don't know what it is exactly but looks interesting roll

It returns the full match even if it's not between brackets isn't it?

Done
http://www.den4b.com/wiki/ReNamer:Regul … kreference

"The expressions $0 refers to the whole original name.
Note: it is not necessary to enclosed them in round brackets () for this use, $0 is just there. "


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB