move files to folders named by date from files
Moderator: DosItHelp
move files to folders named by date from files
hi
I have files named textA_date_time.avi, textB_date_time.avi.... I need move all files to folders which names are create by dates from names from files.
for example: chose date from textA_20120513_120559.avi, create folder with name: 20120513 and move all files with this date (there are also files with different time, but same date)
do the same with textB_date_time.avi ....
any ideas?
I have files named textA_date_time.avi, textB_date_time.avi.... I need move all files to folders which names are create by dates from names from files.
for example: chose date from textA_20120513_120559.avi, create folder with name: 20120513 and move all files with this date (there are also files with different time, but same date)
do the same with textB_date_time.avi ....
any ideas?
Re: move files to folders named by date from files
Can you make sure there is no further underscore in textA, textB, ...?
Regards
aGerman
Regards
aGerman
Re: move files to folders named by date from files
original names of files are date_time.avi. it is from motion detection from IP camera. I have 2 area of motion detection so I have 2 different names of group of videos. textA_date_time.avi can be date_time.avi, but it can be also textAdate_time.avi.
Re: move files to folders named by date from files
Untested:
Regards
aGerman
Code: Select all
@echo off
for /f "delims=" %%i in ('dir /a-d /b *.avi') do (
set "name=%%~ni"
setlocal EnableDelayedExpansion
set "fdate=!name:~-15,8!"
md "!fdate!" 2>nul
move "!name!.avi" "!fdate!\"
endlocal
)
Regards
aGerman
Re: move files to folders named by date from files
It works. thank you very much
Re: move files to folders named by date from files
is it possible put _ between 20120513? like this 2012_05_13 in folders names
Re: move files to folders named by date from files
Of course. It's just string manipulation again.
Regards
aGerman
Code: Select all
@echo off
for /f "delims=" %%i in ('dir /a-d /b *.avi') do (
set "name=%%~ni"
setlocal EnableDelayedExpansion
set "fdate=!name:~-15,8!"
set "fdate=!fdate:~0,4!_!fdate:~4,2!_!fdate:~-2!"
md "!fdate!" 2>nul
move "!name!.avi" "!fdate!\"
endlocal
)
Regards
aGerman
Re: move files to folders named by date from files
thank you. I have last request: how can I delete this folders after for example 60days?
Re: move files to folders named by date from files
I think it is quite dificult. maybe it can by easyli like this: forfiles /p C:\folder /d -60 /c "cmd /c del @file" but it does not work.
It only delete files inside folders and I must press Y to delete. Is it possible to do without Y ?
It only delete files inside folders and I must press Y to delete. Is it possible to do without Y ?
Re: move files to folders named by date from files
The question is how you want to determine the date? According the folder name you should use the :date2jdate function. According the folder date you could use FORFILES.
Regards
aGerman
Regards
aGerman
Re: move files to folders named by date from files
According the folder date is ok for me. but I don not know how
Re: move files to folders named by date from files
Try
Remove ECHO and PAUSE if you think it would work.
Regards
aGerman
Code: Select all
@echo off
for /f "tokens=1*" %%i in ('forfiles /d -60 /m ????_??_?? /c "cmd /c echo @isdir @path"') do (
if %%i==TRUE ECHO rd /s /q %%j
)
PAUSE
Remove ECHO and PAUSE if you think it would work.
Regards
aGerman
Re: move files to folders named by date from files
mato wrote:I think it is quite dificult. maybe it can by easyli like this: forfiles /p C:\folder /d -60 /c "cmd /c del @file" but it does not work.
It only delete files inside folders and I must press Y to delete. Is it possible to do without Y ?
As aGerman has already shown you the DEL command deletes files. The RMDIR or RD deletes directories. You gotta use the correct tool for the corresponding job.

You wouldn't use a Jack Hammer to pound in a nail.