VBS - 在子文件夹中找到最旧的文件并移动

时间:2014-05-05 16:35:03

标签: vbscript move subdirectory

我正在准备脚本,应该检查几个子文件夹并移动文件进行处理,基于FIFO工作目录。

我的(非常短的,业余的)代码现在看起来像这样。

Dim srcPath,trgtPath,objFile,totalFiles,fso

Set fso = CreateObject("Scripting.FileSystemObject")
srcPath = "C:\terms\"

Set srcFolder = fso.GetFolder(srcPath)
trgtPath = "C:\AutoTerm\Temp"

If fso.GetFolder(srcPath).Files.Count < 1 Then
Wscript.Quit
End If

If fso.GetFolder(trgtPath).Files.Count => 1 Then
Wscript.Quit
End If


Dim oldestFile, oldestDate
For Each objFile In srcPath.Files
If oldestFile = "" Then
Set oldestFile = objFile
Else
If objFile.DateLastModified < oldestFile.DateLastModified Then
Set oldestFile = objFile
End If
End If
Next

oldestFile.Move trgtPath & "\" & oldestFile.Name

Wscript.Quit

我需要这个脚本来搜索trgtPath中的所有子文件夹(c:\ terms),并且只将1个最旧的文件移动到trgtPath。我试过了

 Set Subfldr = srcPath.Subfolders

但它不起作用,总是要求“对象”,当我尝试将For Each更改为文件夹和srcPath.Subfolders时,结果相同。

如果你能帮助我,我将非常感激。先感谢您。

1 个答案:

答案 0 :(得分:0)

srcPath是一个字符串。 srcFolder是您的Folder对象。请改用srcFolder.Files

相关问题