tmpFile = "result.txt" 'temp file
With CreateObject("WScript.Shell")
.CurrentDirectory = rootFolder
.Run "CMD /C DIR /A:D /B /O:-D /T:C > " & tmpFile, 0, True
With CreateObject("Scripting.FileSystemObject")
With .OpenTextFile(tmpFile)
mostRecent = .ReadLine
End With
.GetFile(tmpFile).Delete
End With
.CurrentDirectory = mostRecent
.Run "CMD /C COPY *.* " & dstFolder, 0, False
End With
二手DIR开关:
/A:D = attributes Directory
/B = bare format
/O:-D = order by date/time (newly first)
/O:D = order by date/time (oldest first)
/T:C = sort by Creation
/T:A = sort by Last Access
/T:W = sort by Last Written
0
试试这个:
rootFolder = "C:\root"
dstFolder = "C:\dst"
Set fso = CreateObject("Scripting.FileSystemObject")
Set mostRecent = FindMostRecent(fso.GetFolder(rootFolder))
For Each f In mostRecent.Files
f.Copy fso.BuildPath(dstFolder, f.Name)
Next
Function FindMostRecent(fldr)
Set mrf = fldr
For Each sf In fldr.SubFolders
Set mrsf = FindMostRecent(sf)
If mrsf.DateLastModified > mrf.DateLastModified Then Set mrf = mrsf
Next
Set FindMostRecent = mrf
End Function
2 回答
我发现你把文件夹作为参数传递时遇到了一些困难 . Ansgar Wiechers的例子展示了如何用硬编码值来做到这一点 . 为简单起见,我们通常会在答案中这样做 .
但是如果你喜欢像他们那样动态地传递它们......
...然后在.vbs文件的开头包含此内容:
接下来,通过阅读您的评论,在我看来,您只需要直接的子文件夹,如果是这样,因为在批处理脚本中不太好,我会做这样的事情:
二手DIR开关:
试试这个: