2016-11-17 194 views
0

嗨我試圖從源文件複製文件到目標文件夾。但是當我運行它時,我收到一個錯誤「錯誤的文件名或數字」。將文件從源文件夾複製到目標文件夾

這裏是我的代碼:

Option Explicit 
Dim srcFolder, trgFolder 

srcFolder = "\\sunpowercorp.com\spap\SPMM-QA\Public-Read_Write\SPMM QA Documents\Dominic Yumul\Toshiba Monthly Quality Report" 
trgFolder = "http:\\dms\departments\QUALITY\Quality Ops in the Box\Quality Ops in the Box library\025 SPMM QA Staff Documents\Toshiba Monthly Quality Report" 

CopyFilesAndFolders srcFolder, trgFolder 
WScript.Quit 

Sub CopyFilesAndFolders(ByVal strSource, ByVal strDestination) 
    Dim ObjFSO, ObjFolder, ObjSubFolder, ObjFile, files 
    Dim TargetPath 
    Set ObjFSO = CreateObject("scripting.filesystemobject") 
    'connecting to the folder where is going to be searched 
    Set ObjFolder = ObjFSO.GetFolder(strSource) 
    TargetPath = Replace (objFolder.path & "\", strSource, strDestination,1,-1,vbTextCompare) 
    If Not ObjFSO.FolderExists (TargetPath) Then ObjFSO.CreateFolder (TargetPath) 
    Err.clear 
    On Error Resume Next 
    'Check all files in a folder 
    For Each objFile In ObjFolder.files 
     If Err.Number <> 0 Then Exit For 'If no permission or no files in folder 
     On Error goto 0 
     If CheckToCopyFile (objFile.path, TargetPath & "\" & objFile.name) Then 
      objFSO.copyfile objFile.path, TargetPath & "\" & objFile.name, True 
     End If 
    Next 
    'Recurse through all of the subfolders 
    On Error Resume Next 
    Err.clear 
    For Each objSubFolder In ObjFolder.subFolders 
     If Err.Number <> 0 Then Exit For 'If no permission or no subfolder in folder 
     On Error goto 0 
     'For each found subfolder there will be searched for files 
     CopyFilesAndFolders ObjSubFolder.Path & "\", TargetPath & ObjSubFolder.name & "\" 
    Next 
    Set ObjFile = Nothing 
    Set ObjSubFolder = Nothing 
    Set ObjFolder = Nothing 
    Set ObjFSO = Nothing 
End Sub 

Function CheckToCopyFile(ByVal strSourceFilePath, ByVal strDestFilePath) 
    Dim oFSO, oFile, SourceFileModTime, DestFileModTime 
    CheckToCopyFile = True 
    Set oFSO = CreateObject("scripting.filesystemobject") 
    If Not oFSO.FileExists (strDestFilePath) Then Exit Function 
    Set oFile = oFSO.GetFile (strSourceFilePath) 
    SourceFileModTime = oFile.DateLastModified 
    Set oFile = Nothing 
    Set oFile = oFSO.GetFile (strDestFilePath) 
    DestFileModTime = oFile.DateLastModified 
    Set oFile = Nothing 
    If SourceFileModTime =< DestFileModTime Then CheckToCopyFile = False 
    Set oFSO = Nothing 
End Function 

我不知道是什麼行,我得到的錯誤。

+1

您無法使用FSO將文件複製到Web服務器。 – 2016-11-17 07:12:27

+0

那我該怎麼做? – Karl

+0

這將向您展示如何在最基本的Web服務器上進行交互。您需要知道要發送服務器的內容。它通常是一個post命令。你可以得到Fiddler https://www.telerik.com/,它可以讓你看到正在發送的內容。您可以在這裏使用vbscript來完成瀏覽器正在做的事情。 http://stackoverflow.com/questions/40480969/how-to-read-the-content-of-a-website-using-batch-script – 2016-11-17 09:03:27

回答

0

在Windows Vista和較新的,你應該能夠map SharePoint庫驅動使用WebDAV字母在this blog post描述:

Set net = CreateObject("WScript.Network") 
net.MapNetworkDrive "X:", "\\[email protected]\site\Shared Documents\" 

文件然後複製到使用FileSystemObject方法映射的驅動器。

相關問題