Reputation: 1
I am creating a batch file for task scheduler in Windows 7. The logic is searching files in a folder, if the filename without a specific string, and it's older than 10 days, move the file to another folder.
I've tried so many commands but cannot achieve this (combine the findstr and date condition). And as I am quite new to batch commands. Could anyone please give me some scripts or advice?
Here is what I wrote for moving the files without specific string in the filename, but dont know where to put the date condition:
for /r %Path_new% %%H in ("*.avi") do (echo "%%~nH" |findstr /i "_connID=">nul ||((move /y "%%H" "%Path_achieve%" ) && (echo %date% %time% - %%H has been moved >> Log4BB.txt)) )
And if I put a date condition in a script, it will be like this but cannot get the files with a specific string in the filename:
forfiles /p %Path_new% /m *.avi /d -%Day_noconnid% /c "cmd /c if @fname like '*_connID=*' (echo @path will be moved)" >> Log4BA.txt
For robocopy, I don't know how to specify the files that i want to move. My scripts as below:
for /r %Path_new% %%G in ("*.avi") do (^
echo "%%~nG" |findstr /i "_connID=">nul ||(^
robocopy "%Path_new%"\"%%~nG%%~xG" "%Path_achieve%" /maxage:10 /mov)^
) >> Log4BC.txt
Upvotes: 0
Views: 2502
Reputation: 1
Finally, I got the answer. Robocopy has a /XF that allows me to put the condition for filename.
robocopy %Path_new% %Path_achieve% *.avi /mov /xf "*_connID=*.avi" /minage:%Day_noconnid% /log+:"Log4B.txt"
Working very good now. Thanks Squashman
Upvotes: 0