标题: 请问怎么样才能移动N天前的文件
[打印本页]
作者: l80d
时间: 2007-10-8 20:31
标题: 请问怎么样才能移动N天前的文件
操作系统win2003
目前我的文件夹D:\Logs\下有上万个1k到5k的小文件,
想搞个批处理把它移动到D:\backup\下面.
根据willsort的代码修改如下:
@echo off
if "%1"==":" goto %2
if exist %temp%.\_DateDel.bat %temp%.\_DateDel.bat
%0 : Update 2007-08-20 2007-08-21 2007-08-22 2007-08-23 2007-08-24 2007-08-25 2007-08-26
:Update
setlocal EnableExtensions
set today=%date:~0,10%
if not "%today%"=="%9" %0 : Update %4 %5 %6 %7 %8 %9 %today%
echo %0 : Update %3 %4 %5 %6 %7 %8 %9 >%temp%.\_DateDel.bat
:Delete
for /r %%f in (*.*) do if "%%~tf" LEQ "%3" echo move "%%f" D:\backup\
:End
可是没用,请问该怎么改?
作者: l80d
时间: 2007-10-8 21:34
在坛子里找找,终于搞定了。
MoveOldFiles.cmd
@echo off
if "%1"=="" goto _usage
set dst=.\.
if not "%2"=="" if exist %2\. (set dst=%2\.) else (goto _err1)
for /r %dst% %%f in (*.*) do if %%~tf LSS %1 Move /y %%f D:\backup\ && echo Move %%f
goto _quit
:_usage
echo DelOldFile.cmd move files before assigned folder and date
echo Version 1.0 Copyleft by Climbing
echo syntax: DelOldFile ^<Date^> [target Folder]
echo ^<Date^> Must assigned parameter,Date format:%date%,Files before the assigned date will be move(not include the assigned date)
echo [target Folder] Optional parameter,Assign the folder which files want to be moveed,default is current folder
goto _quit
:_err1
echo Err:Assigned folder:%2 not exist!
:_quit
set dst=
:End
用法:
MoveOldFiles 2007-08-15 D:\Logs
把2007-08-15以前在D:\Logs下的文件,移动到D:\backup\下
还没把文件要移动到文件设为参数
目前这命令只能把所有文件移动到目标文件夹下
不知道高手能不能修改下,保持被移动文件的目录架构?
[
Last edited by l80d on 2007-10-8 at 09:54 PM ]
作者: wudixin96
时间: 2007-10-9 09:04
上面的脚本移动的是几号前的文件,而不是几天前的文件。