中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-25 15:42
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » 请问怎么样才能移动N天前的文件 查看 710 回复 2
楼 主 请问怎么样才能移动N天前的文件 发表于 2007-10-08 20:31 ·  中国 江苏 苏州 电信
初级用户
积分 26
发帖 9
注册 2006-12-08 09:29
19年会员
UID 72913
性别 男
状态 离线
操作系统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

可是没用,请问该怎么改?
2 发表于 2007-10-08 21:34 ·  中国 江苏 苏州 电信
初级用户
积分 26
发帖 9
注册 2006-12-08 09:29
19年会员
UID 72913
性别 男
状态 离线
在坛子里找找,终于搞定了。

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^>
echo ^<Date^> Must assigned parameter,Date format:%date%,Files before the assigned date will be move(not include the assigned date)
echo 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 ]
3 发表于 2007-10-09 09:04 ·  中国 香港 腾讯云
银牌会员
★★★
积分 1,928
发帖 931
注册 2007-01-06 11:46
19年会员
UID 75624
性别 男
状态 离线
上面的脚本移动的是几号前的文件,而不是几天前的文件。
论坛跳转: