ファイル名の先頭などの条件に基づいてファイルを振り分けるバッチファイル

ファイル名で振り分け

set "source=C:\source\"
set "destination=C:\destination\"
mkdir "%destination%" 
setlocal enabledelayedexpansion

for %%f in (%source%*) do (
    set "filename=%%~nf"
    set "subdir=!filename:~0,5!"
    mkdir "%destination%\!subdir!" 2>nul
    move "%%f" "%destination%\!subdir!\"
)
endlocal

拡張子で振り分け

@echo off
set "source=C:\source\"
set "destination=C:\destination\"
mkdir "%destination%"
setlocal enabledelayedexpansion

for %%f in (%source%*) do (
    set "extension=%%~xf"
    set "subdir=!extension:~1!"
    mkdir "%destination%\!subdir!" 2>nul
    move "%%f" "%destination%\!subdir!\"
)
endlocal
pause

ファイルサイズで振り分け

@echo off
set "source=C:\source\"
set "destination=C:\destination\"
mkdir "%destination%\below_1000"
mkdir "%destination%\above_1000"
setlocal enabledelayedexpansion

for %%f in (%source%*) do (
    set "size=%%~zf"
    if %%size%% LSS 1000 (
        move "%%f" "%destination%\below_1000\"
    ) else (
        move "%%f" "%destination%\above_1000\"
    )
)
endlocal
pause

bat,windows

Posted by eightban