Moving Files based on First Letter to Folders

February 4, 2011 at 22:49:32
Specs: Windows 7
I have loads of files I need to move to folders named #(i.e. numeric), A, B and so on. I need a script that will simply find the first letter of the file name and then move it to it's corresponding folder. I have no idea how you would handle the numbered files unless it just picked everything but A-Z. The #-Z folders are already created with hundreds of files in them already. The files to be moved will originate from one folder. There also needs to be prompt if the files exist which let's me choose yes or no for the overwrite.

Example: Move

Adam.xxx
\"A" Folder
/
Arron.xxx

Bob.xxx
\"B" Folder
/
Ben.xxx

Thanks,

-Steve


See More: Moving Files based on First Letter to Folders

Report •


#1
February 4, 2011 at 23:53:48
@echo off > newfile & setLocal enableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b/a-d') do (
set F=%%a & move /-y %%a !F:~0,1!
)


=====================================
Life is too important to be taken seriously.

M2


Report •

#2
February 5, 2011 at 10:39:27
Fantastic but it seems to rename the .bat file to the first letter. I named it Move.bat and it renames it to m and creates another file named n. No ext. on either.

Report •

#3
February 5, 2011 at 22:22:03
[1] Never name a script to an existing command, like MOVE, DIR, DEL.

[2] Don't put the bat in the directory to be processed.


=====================================
Life is too important to be taken seriously.

M2


Report •

Related Solutions

#4
February 6, 2011 at 03:01:23
Yes I figured that out after that, haha, that's why I work with hardware, LOL. I did try it from another folder but it did not seem to work but I will try it again. Again THANK YOU.

Report •

#5
February 6, 2011 at 12:23:10
Well I gave it my best effort. Here are to photos of before the the .bat file run.

Before:

http://i576.photobucket.com/albums/...


After:

http://i576.photobucket.com/albums/...

Also it does not move any files into the folders.


Report •


Ask Question