- @echo off
- rem 批处理保存为ansi编码格式
- set "file=d:\1.txt"
- set "folder=d:\新建文件夹"
- set "DaysAgo=10"
-
- for %%a in ("%file%") do (
- for /f "delims=" %%i in ('powershell -c "Get-Date -UFormat '%%Y-%%m-%%d'"') do (
- copy /y "%file%" "%folder%\%%~na_%%i%%~xa"
- )
- for /f "delims=" %%i in ('powershell -c "Get-Date (Get-Date).AddDays(-%DaysAgo%) -uformat "%%Y-%%m-%%d""') do (
- for /f "delims=" %%b in ('dir /b /a-d "%folder%\%%~na_*-*-*%%~xa"') do (
- if "%%~nb" leq "%%~na_%%i" (
- del "%folder%\%%b"
- )
- )
- )
- )
- pause
- exit
- 参考资料
- http://bbs.bathome.net/viewthread.php?tid=3328
- http://www.bathome.net/viewthread.php?tid=3330
复制代码
|