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

If you need help on how to use the program
Post Reply
dwids
Posts: 3
Joined: 2009-05-03 07:08:15
Location: Australia

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

Post 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!
antp
Site Admin
Posts: 9665
Joined: 2002-05-30 10:13:07
Location: Brussels
Contact:

Post 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
dwids
Posts: 3
Joined: 2009-05-03 07:08:15
Location: Australia

Post by dwids »

Thanks for that. I also have folder names that I wish to apply this to, so I will try that as well.
dwids
Posts: 3
Joined: 2009-05-03 07:08:15
Location: Australia

Post 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
Post Reply