find比昨天使用批处理脚本更新的文件

我正在尝试编写一个批处理脚本,可以从昨天和/或从特定文件夹中的任何特定date开始查找创build/修改/更新的文件。 然后这些文件需要被复制到不同的位置。

我试图使用forfiles命令,但我的XP没有这个命令。

任何帮助都是极好的!

您可以使用Horst Schaeffer出色的wasfile.exe工具:

for /rc:\particular_folder %i in (*.*) do @wasfile.exe %i created after Today-1 > nul && @copy %if:\different_location

您可以根据需要更改创build修改

 WasFile, ver. 2.2 (c) 2006-2007, Horst Schaeffer compares .. the time&date of two files (or directories), the date only, time ignored the date of a file with TODAY-n (days) the time&date of a file with NOW-n (minutes) Examples: WasFile this.zip created before that.zip WasFile this.zip modified after today-8 Syntax: WasFile File1 [Stamp] [not] before|after|sametime File2 [Stamp] [Option] WasFile File1 [Stamp] [not] before|after|sametime today-n [Option] WasFile File1 [Stamp] [not] before|after|sametime now-n Stamp is either: created, modified (default) or accessed (by default second stamp = first stamp) Options to compare date only, ignore time: /DateLocal or /DateUTC (if TODAY is used, default is /DateLocal) Result by errorlevel: 0: true, 1: false, 255: error (message to STDERR) 

顺便说一句,当你把(。),这是否意味着寻找任何格式/种类的文件? 我可以把* .csv而不是只searchCSV文件?

我认为你的意思是(*。*)? 是的,这告诉你你感兴趣的是什么。* .csv将隔离只是csv文件。

你为什么要用@ wasfile.exe,nul,@ copy和switch%i(两个地方)

您可以通过阅读一些网站获得背景信息:
http://www.netikka.net/tsneti/http/tsnetihttpprog.php#batch
http://www.netikka.net/tsneti/info/tscmd.php

谷歌批处理教程更多的网站。

在batch file中,@ 命令意味着不要将命令行回显到屏幕上。 否则,你会看到你所要求的以及结果是什么。 &&表示“如果命令成功,则处理以下内容”,并通过错误级别确定。 如果我想“不成功”,我会用||

在这种情况下,您将代码读取为:文件是否比我的目标date更新,如果是(&&),则将其复制到某个位置。 不要显示我的命令输出“> nul”
好?

使用VBScript及其GetFile()和DateDiff()函数很容易实现。 VBScript是XP本地的。

 Option Explicit On Error Resume Next Err.Clear processFolder "c:\temp" WScript.Quit Function processFolder( strPath ) On Error Resume Next Dim objFSO Dim objFolder Dim intRc Dim colFiles Dim objFile intRc = 0 Set objFSO = CreateObject( "Scripting.FileSystemObject" ) If Err.Number <> 0 Then intRc = -1 Err.Clear Else Set objFolder = objFSO.GetFolder( strPath ) If Err.Number <> 0 Then intRc = -2 Err.Clear Else Set colFiles = objFolder.Files If Err.Number <> 0 Then intRc = -3 Err.Clear Else For Each objFile in colFiles checkFile strPath, objFile.Name, (24 * 60 * 60) Next Set colFiles = Nothing End If Set objFolder = Nothing End If Set objFSO = Nothing End If processFolder = intRc End Function Function checkFile( ByVal strPath, strName, intThreshold ) On Error Resume Next Dim objFSO Dim objFile Dim intRc Dim strFileName Dim intModificationPeriodSecs Dim objDateLastModified intRc = 0 strFileName = strPath & "\" & strName Set objFSO = CreateObject( "Scripting.FileSystemObject" ) If Err.Number <> 0 Then intRc = -1 Err.Clear Else Set objFile = objFSO.GetFile( strFileName ) If Err.Number <> 0 Then intRc = -2 Err.Clear Else 'intRc = objFile.Size objDateLastModified = objFile.DateLastModified intModificationPeriodSecs = DateDiff( "s", objDateLastModified, Now ) If intModificationPeriodSecs > intThreshold Then WScript.Echo "File [" & strFileName & "] last modified [" & intModificationPeriodSecs & "] seconds ago." End If Set objFile = Nothing End If Set objFSO = Nothing End If checkFile = intRc End Function