Answer the question
In order to leave comments, you need to log in
How to sort files by file modification date into folders, where are the folders with the name of the modification date through bat?
Good day! I ask for help in writing a bat script that took all the files from the folder and sorted by the date of modification of each file into its own folder with the name of the date, like DD.MM.YY. There are many files.
For example, there are files with modification date:
D:\\test\FILE01.avi //15.09.2019
D:\\test\FILE12.avi //18.09.2019
D:\\test\FILE06.avi //01.04.2019
D:\\test\FILE18.jpg //15.09.2019
D:\\test\FILE04.avi //26.08.2019
...
D:\\test\01.04.19\FILE06.avi
D:\\test\26.08.19\FILE04.avi
D:\\test\15.09.19\FILE01.avi
D:\\test\15.09.19\FILE18.jpg
D:\\test\18.09.19\FILE12.avi
...
//сохраняем текущую папку в переменную startdir
set startdir=%cd%
//тут какой-то код-цикл по поиску файлов,
//возможно должна быть переменная %%file
//с именем текущего файла в цикле
//собираем дату в формате DD.MM.YY
for /F "tokens=1-4 delims=." %%A in (‘date /t’) do (
set DateDay=%%A
set DateMonth=%%B
set DateYear=%%C
)
//ругается на точки
set CurrentDate=%DateDay%.%DateMonth%.%DateYear%
//проверяем не создана ли папка. Если нет, то создаем папку DD.MM.YY в текущей директории
if not exist "startdir\%CurrentDate%" mkdir %CurrentDate%
//перемещаем файл %%file в созданную папку DD.MM.YY
move startdir\%%file startdir\%CurrentDate%\%%file
Answer the question
In order to leave comments, you need to log in
See for /?
specifically the modifier of the cycle variable % ~
tIset /?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question