Board logo

标题: [文件操作] [已解决]批处理怎样备份最近7天的文件? [打印本页]

作者: zhou926    时间: 2013-9-9 17:48     标题: [已解决]批处理怎样备份最近7天的文件?

本帖最后由 zhou926 于 2013-9-11 10:47 编辑

将E盘中最近7天内的压缩文件备份到D盘下面,用批处理怎么写
作者: batman    时间: 2013-9-9 21:35

请楼主先搜索再提问,OK!
作者: zhou926    时间: 2013-9-10 09:55

回复 2# batman


    我刚看了下那个帖子,他的方法是先备份所有的文件,然后删除指定天数之前的文件,这样的方式我会弄,但是我的E盘数据太多,如果全部备份过去,有好几个G,所以我是想,能不能直接就复制7天内的数据,那样就不用复制所有的文件,然后删除那么麻烦了
作者: Batcher    时间: 2013-9-10 10:18

参考:
http://www.bathome.net/thread-3334-1-1.html
作者: batman    时间: 2013-9-10 16:40

看了楼上链接的代码不知道自己改?伸手派?
作者: zhou926    时间: 2013-9-10 18:10

本帖最后由 zhou926 于 2013-9-10 18:31 编辑

回复 5# batman


    我用的Batcher的方案5的代码改的:
@echo off

set SrcDir=E:\

set DaysAgo=7

forfiles /p %SrcDir% /d -%DaysAgo% /c "cmd /c copy @path d:\"
pause
但是这样是复制的7天之前的文件,不能复制最近7天内的文件
作者: weichenxiehou    时间: 2013-9-10 21:09

看到楼主被批得实在可怜,态度又这么好,难得啊,帮你写个吧:
  1. @echo off
  2. echo,WScript.Echo DateAdd("d",-7,Date)>"%temp%\$.vbs"
  3. for /f %%a in ('CScript //nologo "%temp%\$.vbs"') do (
  4.   forfiles /p e:\ /d +%%a /c "cmd /c copy @path d:\"
  5. )
  6. del "%temp%\$.vbs"
复制代码

作者: Batcher    时间: 2013-9-10 21:32

回复 6# zhou926


根据帮助文档,你分别试试加号和减号。

    /D    date          Selects files with a last modified date greater
                        than or equal to (+), or less than or equal to
                        (-), the specified date using the
                        "yyyy/MM/dd" format; or selects files with a
                        last modified date greater than or equal to (+)
                        the current date plus "dd" days, or less than or
                        equal to (-) the current date minus "dd" days. A
                        valid "dd" number of days can be any number in
                        the range of 0 - 32768.
                        "+" is taken as default sign if not specified.
作者: zhou926    时间: 2013-9-11 09:25

回复 7# weichenxiehou


    非常感谢,你的代码可以用!
作者: zhou926    时间: 2013-9-11 09:31

回复 8# Batcher


   加号或者减号都不行,-7是复制今天减7天之前的文件,+7是复制今天加7天后的文件,两者都不能符合要求
作者: ww0000    时间: 2013-9-13 11:16

回复 7# weichenxiehou


    不能用呀,楼主测试过吗?
作者: weichenxiehou    时间: 2013-9-13 17:52

回复 11# ww0000
看一看你的系统自带forfiles.exe不,没有就下一个放到同目录下,win7是自带的。




欢迎光临 批处理之家 (http://bbs.bathome.net/) Powered by Discuz! 7.2