moving files into folders with the same name

February 21, 2011 at 12:11:53
Specs: Windows XP
Hi,

I have hundreds of files that need to be moved into folders.

This is the kind of files I have

00010abc1.txt
00010abc2.txt
00010abc3.txt

00020abc1.txt

00030abc1.txt
00030abc2.txt

00040abc1.txt

00050abc1.txt
00050abc2.txt
00050abc3.txt

And I want to put them into folders named as follow:

00010
00020
00030
00040
00050

I am using WIndows

I am a real newbie in programming so any help would be appreciated. Sorry for the basic english, I'm french.

Thanks a lot in advance!


See More: moving files into folders with the same name

Report •

#1
February 21, 2011 at 13:45:15
create a batch file with below contents and run it from the folder where you have all the text files.
::=====================================================
@echo on

for /f "tokens=1 delims=a" %%a in ('dir /b *.txt') do (
md %%a
move %%a* %%a\
)
::========================================================

It will search for all the files and take the name before a (like 00050) ,create a directory with that name , if already present then will show error but that can be ignored and finaly move the file to newly created folder.

Let me know if it works for you.. I asumed all the files have a "A" after the numbers.

Subhash Chandra.


Report •

#2
February 21, 2011 at 14:31:15
It worked perfectly. Awesome!

Thank you very much.

Tim


Report •
Related Solutions


Ask Question