返回列表 上一主題 發帖

[發問] 二台電腦之間檔案複製有時不行呢?

[發問] 二台電腦之間檔案複製有時不行呢?

本帖最後由 dechiuan999 於 2014-8-21 16:41 編輯

各位大大好:
TEST.rar (22.9 KB)
小弟想利用net指令來

本帖最後由 dechiuan999 於 2014-8-21 18:31 編輯

TEST.rar (21.79 KB)
  1. Sub mXcopy()   
  2.     Dim Wsh As IWshRuntimeLibrary.WshShell  '此宣告是否有誤呢?
  3.     Dim sourceFile As String
  4.     Dim destinationFile As String
  5.     Dim fs As Scripting.FileSystemObject    '此宣告是否有誤呢?
  6.     Dim cmdStr
  7.     Dim retVal
  8.     Set Wsh = CreateObject("WScript.Shell")
  9.         Wsh.Run "cmd /c net use O: \\multibay\SCAN"        
  10.         
  11.         sourceFile = "O:\" & mTb.Text & ".PDF"
  12.         destinationFile = "D:\TEMP\."
  13.         Set fs = CreateObject("scripting.filesystemobject")
  14.         If fs.FileExists(sourceFile) Then
  15.             cmdStr = "cmd /c copy " & sourceFile & " " & destinationFile
  16.             retVal = Shell(cmdStr, 0)
  17.         Else
  18.             MsgBox "輸入的中文標籤檔案名稱不存在" & vbCrLf & "請重新輸入指定的中文標籤"
  19.         End If
  20.         
  21.         Wsh.Run "cmd /c net use O: /delete"
  22.         
  23.         Set fs = Nothing
  24.         Set Wsh = Nothing
  25.       
  26. End Sub
複製代碼
回復 1# dechiuan999

補充說明 如附檔

TOP

回復 3# luhpro


    謝謝大大的提示
小弟明日回公司後再試試

感恩大大!

TOP

回復 3# luhpro


    謝謝大大。
小弟今日在公司
依大大的方式,其
結果還是相同。
現小弟改用下列方式
運作
  1. '設定引用項目 Windows Script Host Object Model
  2.    
  3.     Dim myWsh As IWshRuntimeLibrary.WshShell
  4.     Dim myStr As String
  5.     Dim myFso     As Scripting.FileSystemObject
  6.     Dim myName    As String
  7.     Dim myNewPath As String
  8.    
  9.    
  10.     Set myWsh = CreateObject("Wscript.Shell")
  11.     myStr = "\\multibay\scan"               '指定資料夾
  12.     'Debug.Print CurDir
  13.     myWsh.CurrentDirectory = myStr
  14.     'Debug.Print CurDir
  15.    
  16.     Set myFso = New Scripting.FileSystemObject
  17.     myName = "\\multibay\scan\T-1.PDF"      '複製來源檔案
  18.     myNewPath = "D:\TEMP\"        '指定複製目標
  19.     myFso.CopyFile myName, myNewPath, OverWriteFiles:=True
  20.     '不能使用Mask字元
  21.     'myFso.GetFile(myName).Copy myNewPath, OverWriteFiles:=True
  22.     Set myFso = Nothing                            '物件的釋放
  23.     Set myWsh = Nothing                            '物件的釋放
複製代碼

TOP

        靜思自在 : 君子如水,隨方就圓,無處不自在。
返回列表 上一主題