How to move files into subdirectories in batch job?
November 7, 2006 10:14 AM
Subscribe
I have a large number of files sitting in a directory. I'd like to automate the following: Take each file, create a subdirectory for it (the name can be anything), and move the file into that subdirectory. Repeat until every file is moved into its own subdirectory. This is in Windows XP (although obviously I could use a .BAT file in MS-DOS).
Thanks
posted by mikeand1 to computers & internet (24 comments total)
4 users marked this as a favorite
for %i in (*) do mkdir "%~ni" & move "%i" "%~ni"
This assumes that all the filenames have extensions, and the folder names it creates are the same as the filenames, but without the extensions.
So if you have
test1.txt
test2.txt
test3.txt
They'll end up in
test1\test1.txt
test2\test2.txt
test3\test3.txt
posted by llamateur at 10:25 AM on November 7, 2006