我想运行批处理脚本,以递归方式将过去24小时内的新文件名或修改后的文件名输出到文本文档中。请指教!
答案 0 :(得分:1)
您可以编写一个vbscript文件来执行此操作。
将filesystemobject用于get file信息。然后检查datecreated或datelastmodified值是否小于一天,检查返回值减去now是否小于1.然后使用代码here如果文件名是新的或新修改的,请将文件名写入文本文件。
代码:
Dim objFS, objOutput, objFolder, objFile, objTS, strListFilePath, strFolderToCheck
strListFilePath = "C:\NewFilesList.txt" ' or whatever
strFolderToCheck = "C:\" ' or whatever
Set objFS = CreateObject("Scripting.FileSystemObject")
Set objFolder = objFS.GetFolder(strFolderToCheck)
objFS.CreateTextFile strListFilePath
Set objOutput = objFS.GetFile(strListFilePath)
Set objTS = objOutput.OpenAsTextStream(2, -2) 'This means open for writing and use the default tristate value
CheckFolder(objFolder)
objTS.Close
Set objFS = Nothing
Set outFolder = Nothing
Set objOutput = Nothing
Set objTS = Nothing
Sub CheckFolder(objThisFolder)
Dim objSubFolder
for each objSubFolder in objThisFolder.SubFolders
CheckFolder(objSubFolder)
next
for each objFile in objThisFolder.Files
if (Now - objFile.DateCreated & vbCrLf < 1) or (Now - objFile.DateLastModified < 1) then
'Less than 24hrs old
objTS.WriteLine(objFile.path)
end if
next
End Sub
答案 1 :(得分:1)
这应该提供一个列表 - c:\ aaa不存在并且应该存在。 将c:\ files更改为源文件夹并更改日期以适应。
xcopy /s/h/e/k/f/c/l /d:04-28-2013 "c:\files" c:\aaa\ >file.txt