C
C
CKrabs2019-09-27 08:48:35
cmd/bat
CKrabs, 2019-09-27 08:48:35

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
...

in the end it should look like:
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
...

the batch file will be launched from the directory itself with files.
I am not strong in bat, but non-working sketches turned out to be of the form:
clumsy sketch
//сохраняем текущую папку в переменную 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

2 answer(s)
R
res2001, 2019-09-27
@CKrabs

See for /?
specifically the modifier of the cycle variable % ~
tI
set /?

A
anykey_ua, 2019-09-27
@anykey_ua

Already the eye twitched)))
And why not in the direction of Powershell, the functionality is an order of magnitude wider and more convenient

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question