Page 1 of 1

Move files to new folders based on first char of file name

Posted: 2009-05-03 07:20:04
by dwids
Hello,

Is it possible to use Ant Renamer to move files based on the first letter of their name, to a (new) folder with that letter as its name? For example,

From:

Code: Select all

D:\Reports\king.txt
D:\Reports\Kong.dat
D:\Reports\Mountain.txt
etc
To:

Code: Select all

D:\Reports\k\king.txt
D:\Reports\k\Kong.dat
D:\Reports\m\Mountain.txt
etc
Note the little cASe change :-) I don't want two k folders (k and K), just the lower case one.

I can use a Regex to extract the first character, and can use it to create the new Folder, but it then removes that Char from the file name plus I can't work out the (folders) Case change from K to k. Is this possible?

Thanks!

Posted: 2009-05-03 09:13:56
by antp
On Windows there is no case-difference so k and K are the same folder.
You can later rename the folders to put them in lowercase in case some were created in uppercase.

You can either insert a \ in 2nd position, and then later add folder name in beginning of the name, but then you'll potentially lose the case of the first letter.
Or as you said use Regexp:
(.)(.*)
replaced by
$1\\$1$2

Posted: 2009-05-03 21:11:46
by dwids
Thanks for that. I also have folder names that I wish to apply this to, so I will try that as well.

Posted: 2009-05-03 21:17:25
by dwids
...I also have folder names that I wish to apply this to, so I will try that as well.
...and it works just fine