在一些朋友的帮助下,我做了这个代码来根据文件扩展名将文件复制到不同的文件夹。我打算每十分钟运行一次这个脚本,所以每当它复制一个新文件时,它应该以文本格式记录到驱动器 C。这可能吗?请帮帮我。
Set fso = CreateObject("Scripting.FileSystemObject")
Set testfolder = CreateObject("Scripting.Dictionary")
testfolder.CompareMode = vbTextCompare 'case-insensitive
testfolder.Add "env", "D:\env"
testfolder.Add "ikey", "D:\key"
'fso.CreateFolder(testfolder)
CopyFiles fso.GetFolder("D:\source")
Sub CopyFiles(fldr)
For Each f In fldr.Files
basename = fso.GetBaseName(f)
extension = fso.GetExtensionName(f)
If testfolder.Exists(extension) Then
dest = fso.BuildPath(testfolder(extension), f.Name)
If Not fso.FileExists(dest) Then f.Copy dest
End If
Next
For Each sf In fldr.SubFolders
CopyFiles sf
Next
End Sub