.bat file sorting files into folders

前端 未结 2 1225
误落风尘
误落风尘 2021-01-17 02:16

For my picture collection I want to have all pictures in a folder automatically sorted into folders by date. Luckily the files are already named after the timestamp:

2条回答
  •  旧巷少年郎
    2021-01-17 02:29

    Here's another possibility how you could do this using delayed expansion and substrings:

    SETLOCAL ENABLEDELAYEDEXPANSION
    for %%a in (*.jpg) do (
        set f=%%a
        set g=!f:~0,10!
        md "!g!" 2>nul
        move "%%a" "!g!"
    )
    

    The first line enables the syntax using ! instead of % and has the effect to interpret the value of the variable not as the first line of the block is executed (standard batch behavior), but only when the line itself is executed.

    !f:~0,10! is the syntax to obtain a substring - the dates you're after are always 10 characters long.

提交回复
热议问题