Код: Выделить всё
'===================================================
' Копирование файлов\папок (в т.ч. из ярлыков)
'
' Параметры:
' {файл-список} {целевая папка}
'
' Пример параметров при вызове из TC:
' %L "%T"
'===================================================
Sub xCopy (Path, TargetPath)
Dim lnkName, xFolder, colFiles, objFile, colFolders, objFolder, res
if Canceled then Exit Sub
If LCase(FSO.GetExtensionName(Path)) = "lnk" Then
lnkName = Replace(FSO.GetFileName(Path), ".lnk", "")
Path = WSH.CreateShortcut(Path).TargetPath
If FSO.FileExists(Path) then lnkName = lnkName & "." & FSO.GetExtensionName(Path)
End If
If Right(Path, 1) = "\" Then Path = Left(Path, Len(Path) - 1)
If FSO.FileExists(Path) Then
if lnkName = "" then lnkName = FSO.GetFile(Path).Name
If FSO.FileExists(TargetPath & lnkName) and not ReplaceAll Then
res = msgbox ("File " & FSO.GetFile(Path).Name & " already exists", vbYesNoCancel, "Replase all")
Select Case res
Case 6 ' Yes
ReplaceAll = true
FSO.CopyFile Path, TargetPath & lnkName
Case 2 ' Cancel
Canceled = true
Exit Sub
End Select
else
FSO.CopyFile Path, TargetPath & lnkName
End If
End If
If FSO.FolderExists(Path) Then
Set xFolder = FSO.GetFolder(Path)
Set colFiles = xFolder.Files
Set colFolders = xFolder.subFolders
if lnkName = "" then lnkName = FSO.GetFolder(Path).Name & "\"
if Not FSO.FolderExists(TargetPath & lnkName) then FSO.CreateFolder(TargetPath & lnkName)
For Each objFolder in colFolders
xCopy objFolder, TargetPath & lnkName & "\"
Next
For Each objFile in colFiles
xCopy objFile, TargetPath & lnkName & "\"
Next
Set colFolders = Nothing
Set colFiles = Nothing
Set xFolder = Nothing
End If
End Sub
Dim WSH, FSO, FF, ReplaceAll, Canceled
if WScript.Arguments.count < 2 then WScript.Quit 1
Set FSO = CreateObject("Scripting.FileSystemObject")
Set WSH = CreateObject("WScript.Shell")
Set FF = FSO.OpenTextFile(WScript.Arguments(0), 1)
ReplaceAll = false
Canceled = false
Do While Not FF.AtEndOfStream
xCopy FF.ReadLine, WScript.Arguments(1)
Loop
FF.Close
Set FF = Nothing
Set WSH = Nothing
Set FSO = Nothing
WScript.Quit 0