如下程序,移动c:\data下所有文件到 c:\processed. 但有部分文件重复。已知文件名重复的文件内容也是完全相同的,如何覆盖c:\processed下重复的文件呢?
sub filemove()
dim pathd,path3
pathd="c:\data"
path3="c:\processed"
Call movefile(pathd, "*.*", path3)
end sub
Sub movefile(PTH, FILES, PTH2)
Dim MyFileObject
Set MyFileObject = CreateObject("Scripting.FileSystemObject")
MyFileObject.movefile PTH & "\" & FILES, PTH2 & "\"
End Sub
同意楼上看法,先判断是否存在,您说“文件名重复的文件内容也是完全相同的”,所以如果判断 c:\processed中已有,则不移动:
Sub movefile(PTH, FILES, PTH2)
Dim MyFileObject
Set MyFileObject = CreateObject("Scripting.FileSystemObject")
For Each file In MyFileObject.getfolder(PTH).FILES
If Dir(PTH2 & "\" & Dir(file)) = "" Then ‘判断PTH2中是否已有
MyFileObject.movefile PTH & "\" & Dir(file), PTH2 & "\"
End If
Next
End Sub
Sub movefile(PTH, FILES, PTH2)
Dim MyFileObject
Set MyFileObject = CreateObject("Scripting.FileSystemObject")
For Each file In MyFileObject.getfolder(PTH).FILES
If Dir(PTH2 & "\" & Dir(file)) = "" Then ‘判断PTH2中是否已有
MyFileObject.movefile PTH & "\" & Dir(file), PTH2 & "\"
End If
Next
End Sub
温馨提示:答案为网友推荐,仅供参考