CMD Command to create folder for each file and move file into folder
I need a command that can be run from the command line to create a folder for each file (based on the file-name) in a directory and then move the file into the newly created folders.
Example :
Starting Folder:
Dog.jpg
Cat.jpg
The following command works great at creating a folder for each filename in the current working directory.
for %i in (*) do md "%~ni"
Result Folder:
\Dog\
\Cat\
Dog.jpg
Cat.jpg
I need to take this one step further and move the file into the folder.
What I want to achieve is:
\Dog\Dog.jpg
\Cat\Cat.jpg
Can someone help me with one command to do all of this?
The second command would be
for %i in (*) do move "%i" "%~ni"
EDIT: Added "" for the %i, based on and31415's comment. tnx.
Just execute these commands in series:
For creating the folders for each file:
for %i in (*) do mkdir "%~ni"
For moving each file to its folder:
for %i in (*) do move "%i" "%~ni"