It's been a long time since I've used DOS (except for getting games running via DOSBox), so I've forgotten almost everything I knew about DOS, but I'm hoping that someone on here will be kind enough to write a BAT file for me (to be run in a DOS window (i.e. not the games program DOSBox, but a Windows prompt box), please.
I'm looking for a BAT file that creates folders (inside the current folder) and moves a given number of files into each sub folder.
What I mean is, say I have a folder
d:\download\Doom\
with lots of .zip files in it, then I'd like a BAT file that I could put into that folder, run it and it would create a folder called
d:\download\Doom\1
and move twenty-five (or any other number, which is editable in the BATch file) files into that folder, the it would create
d:\download\Doom\2
and move twenty-five more files in to that folder, etc, until all of the files have been moved at which point the BATch file ends.
Thanks for any help.
Looking for a BAT file to MOVE files into new folders
Moderator: DosItHelp
Re: Looking for a BAT file to MOVE files into new folders
Kerr Avon wrote:<...> to be run in a DOS window (i.e. not the games program DOSBox, but a Windows prompt box) <...>

Kerr Avon wrote:I'm looking for a BAT file that creates folders (inside the current folder) and moves a given number of files into each sub folder.
Kerr Avon wrote:<...> I'd like a BAT file that I could put into that folder, run it and <...>
Code: Select all
@echo off
setlocal enableextensions
set number=25
for /f "delims=" %%i in ('"2>nul dir/a-d/b"') do (
if not "%%i"=="%~nx0" (
set/a x+=1
for /f %%j in ('"set/a (x-1)/number+1"') do>nul 2>&1 (
md %%j
move "%%i" %%j\
)
)
)
endlocal
exit /b
Re: Looking for a BAT file to MOVE files into new folders
I had this for my own tasks and am just including it here:
It will create folders like the following:
1025\
1050\
1075\
1100\
1125\
1150\
1175\
1200\
1225\
1250\
1275\
1300\
Code: Select all
@echo off
:: moves all files into numbered folders of 25 in each
setlocal enabledelayedexpansion
set num=25
set c=999
for %%a in (*) do (
if not "%%~nxa"=="%~nx0" (
set /a c=c+1
set /a d=c %% %num%
if !d! equ 0 set f=!c!&md !f!
move "%%a" "!f!" >nul
)
)
echo moved
pause
goto :EOF
It will create folders like the following:
1025\
1050\
1075\
1100\
1125\
1150\
1175\
1200\
1225\
1250\
1275\
1300\
Re: Looking for a BAT file to MOVE files into new folders
Yury, that is fantastic! I've just tried it and it did exactly what I wanted.Thanks so much for that.
Foxidrive, I've not tried your program, as Yury's worked, but I'll keep yours too, in case Yury's fails (maybe if the filename's of some files are too long, or the extensions are too long, or if Yury's can't cope with more than a given number of files, etc - with PCs you can never be sure of success!).
Thanks both of you for your time and effort, I really appreciate it.
Foxidrive, I've not tried your program, as Yury's worked, but I'll keep yours too, in case Yury's fails (maybe if the filename's of some files are too long, or the extensions are too long, or if Yury's can't cope with more than a given number of files, etc - with PCs you can never be sure of success!).
Thanks both of you for your time and effort, I really appreciate it.