User login

Kопирование файлов

Код:

InitialFolder = "\\SERVER\FOLDER"
TargetFolder = "C:\FOLDER"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShellApp = CreateObject("Shell.Application")

CopyFiles InitialFolder

Sub CopyFiles(FolderPath)
Set objFolderItems = objShellApp.NameSpace(FolderPath).Items()
For Each objFolderItem In objFolderItems
If objFolderItem.IsFolder And LCase(Right(objFolderItem.Name, 4)) <> ".zip" Then
CopyFiles objFolderItem.Path
Else
Set objFile = objFSO.GetFile(objFolderItem.Path)
CopyFile objFolderItem.Path
End If
Next
End Sub

Sub CopyFile(FilePath)
SubPath = Mid(FilePath, Len(InitialFolder) + 1)
TargetPath = TargetFolder & SubPath
FolderPath = objFSO.GetParentFolderName(TargetPath)
If Not objFSO.FolderExists(FolderPath) Then
CreateFolder FolderPath
End If
' если у файла назначения есть атрибут ReadOnly, снимаем его
If objFSO.FileExists(TargetPath) Then
Set objFile = objFSO.GetFile(TargetPath)
If objFile.Attributes And 1 Then
objFile.Attributes = objFile.Attributes - 1
End If
End If
objFSO.CopyFile FilePath, TargetPath, True
End Sub

Sub CreateFolder (FolderPath)
On Error Resume Next
ParentFolder = objFSO.GetParentFolderName(FolderPath)
If Not objFSO.FolderExists(ParentFolder) Then
CreateFolder ParentFolder
End If
objFSO.CreateFolder FolderPath
End Sub