- '指定文件目录复制工具(可用户基于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
新闻热点
疑难解答