我无法访问要从中复制某些文件的网络文件夹。我已经汇总了以下代码,现在只打印出今天创建的特定文件。
我遇到的问题是访问网络文件夹,其常规文件路径完美无缺,但当我将其换成网络映射文件夹时,它会崩溃。
Sub NetworkFiles()
Dim n As String, msg As String, d As Date
msg = ""
Set FSO = CreateObject("Scripting.FileSystemObject")
Set fils = FSO.GetFolder("\\corp-server\HostingFolder").Files '("C:\FILES") works perfectly
For Each fil In fils
n = fil.name
n = Left(n, 24)
d = fil.DateLastModified 'DateCreated
If n = "FILE_CHARACTERS_ARE_RANDOM_AFTER_THIS_POINT" Then
If d >= Date Then
msg = msg & n & vbTab & d & vbCrLf
End If
End If
Next fil
If msg = "" Then
MsgBox "No new files"
Else
MsgBox msg
End If
Set FSO = Nothing
End Sub
已解决 - 在包含5k +文件的整个文件夹中非常快速地循环
ANSWER
Sub LoopThroughFiles()
Dim file As Variant
Dim fso As Object
Source = "\\networkpath\test"
file = Dir(Source)
destloc = "C:\test\folder"
msg = ""
While (file <> "")
If InStr(file, "TEST_partOfTheFileString" & Format(Date, "YYYYMMDD")) > 0 Then
FileCopy Source & file, destloc & file
msg = msg & file & vbCrLf
End If
file = Dir
Wend
MsgBox msg & "Files Copied"
End Sub