Batch script to all files in the specified directory split multiple subdirectories

OFF @echo
TITLE batch script splits the specified directory of all files to multiple subdirectories Author: Steven.liao
REM open CMD of delayed environment variable function, use the "!!" get dynamically generated variable
setlocal ENABLEDELAYEDEXPANSION

SET Dir=%1
SET DirCount=0
SET DirNew=0
SET DirNewName=""

%% the Dir echo
the SET / P = Number The number of inputs of each folder in the paper:

for /f “delims=” %%i in (‘dir %1 /a-d /b /s’) do @set /a DirCount+=1

echo %Number%

echo DirCount:%% DirCount
echo DirNewName:% DirNewName%

SET N=0
for /f “delims=” %%i in (‘dir %1 /a-d /b /s’) do (

rem echo! N!
rem echo% Number%

set /a c= N %% %Number%
rem echo c=!c!

if! c! == 0 (
echo mkdir%% you! DirNew!
Set / and DirNewName =! DirNew!
Echo DirNewName: DirNewName!
Mkdir%% you! DirNew!
)

rem echo move %%i %Dir%!DirNewName!
move %%i %Dir%!DirNewName!
rem echo “FILE:%%i”
set /a N+=1
if !c! == 0 (
set /a DirNew+=1
)

)

pause

Reference:
Classic .BAT batch automatic shutdown

Published 19 original articles · won praise 5 · Views 515

Guess you like

Origin blog.csdn.net/WBKJ19970108019/article/details/103270238