I have this code
pushd "C:\Folders\"
for %%j in (*) do (
md "%%~nj"
move "%%j" "%%~nj"
)
popd
pause
exit
This move files with the same name into a folder with the same name, if the folder does not exist it will create a new folder. Ok great.
This issue I have is that I want the same function as above however I only was it to look at the first 4 characters. E.g.
1234 - sample.jpg
1234 - sample-sm.jpg
1234 - sample-new.jpg
1234 - sample-right.jpg
1235 - sample.jpg
1234 files will be moved to the same folder as the first 4 characters are the same, however 1235 will be moved to a new folder because the fist for characters are different.
Thank you
@echo off
setlocal enabledelayedexpansion
pushd "C:\Folders\"
for %%a in (*) do (
set fldr=%%~na
set fldr=!fldr:~0,4!
md "!fldr!"
move "%%a" "!fldr!"
)
popd
pause
exit
However it creates new folders with the first 4 letters and moves the files to these created folders… It does move everything with the same first 4 letters to the correct folder.
So no I need it NO to make a directory but to move it to the already create directory.
Read
HELP SETand then try the following code as an starting point to build your solution…you will need to cope with duplicated names that may occur.
try it, test extensively and remove the
ECHOcommands.