简体   繁体   中英

Windows batch file: move files that older than 10 days and the filename without a specific string

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM