- '指定文件目錄復制工具(可用戶基于svn版本管理的項目做增量發布用途使用)
- '作者:許果
- '日期:2010-11-26
- Sub copyfiles()
- On Error GoTo errorflag
- '指定目標文件的行號
- Dim i As Integer
- '指定目標文件的目錄的長度變量
- Dim j As Integer
- '目錄名稱數組,生成目標文件的過程目錄名字列表
- Dim directoryNameArray() As String
- '指定的目標文件部分文件路徑名稱
- Dim relativeFilePath As String
- '臨時目錄名稱
- Dim tempDirectoryName As String
- For i = 0 To Cells(3, 2) - 1
- tempDirectoryName = ""
- '獲得指定的目標文件的路徑名稱
- relativeFilePath = Cells(4 + i, 2)
- If relativeFilePath = "" Then
- Exit For
- End If
- relativeFilePath = Replace(relativeFilePath, "/", "/")
- directoryNameArray = Split(relativeFilePath, "/")
- '如果拷貝的目標文件件路徑的目錄不存在,就依次建立相應的目錄文件
- For j = 0 To UBound(directoryNameArray) - 1
- tempDirectoryName = tempDirectoryName & "/" & directoryNameArray(j)
- If Dir(Cells(2, 2) & tempDirectoryName, vbDirectory) = "" Then
- MkDir Cells(2, 2) & tempDirectoryName
- End If
- Next j
- '設置需要復制的源文件路徑和目標路徑
- Dim destinationFileFullPath As String
- Dim sourceFileFullPath As String
- sourceFileFullPath = Cells(1, 2) & tempDirectoryName & "/" & directoryNameArray(j)
- destinationFileFullPath = Cells(2, 2) & tempDirectoryName & "/" & directoryNameArray(j)
- '復制文件
- FileCopy sourceFileFullPath, destinationFileFullPath
- Next i
- MsgBox "指定的文件目錄已復制完畢"
- GoTo finished
- Exit Sub
- errorflag:
- MsgBox sourceFileFullPath & (i + 4)
- finished:
- End Sub
新聞熱點
疑難解答