Я пытаюсь скопировать несколько файлов по следующему пути:Копирование 2 файлов в пути текущего профиля пользователя
C: \ Users \ имя пользователя \ AppData \ Roaming \ Macromedia \ Flash Player \ WWW. macromedia.com \ Bin \ adobeconnectaddin
Я использую VBS и сценарий, я использую это следующим образом:
DestinationFile1 = ("C:\Users" + Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin\adobeconnectaddin.exe")
DestinationFile2 = ("C:\Users" + Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin\digest.s")
SourceFile1 = "adobeconnectaddin.exe"
SourceFile2 = "digest.s"
path=CreateObject("WScript.Shell").ExpandEnvironmentStrings("%UserProfile%")
DestinationPath = ("C:\Users" + path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin")
Dim objNetwork
Dim userName
Dim FSO
Dim Folder
Set fso = CreateObject("Scripting.FileSystemObject")
Set objNetwork = CreateObject("WScript.Network")
userName = objNetwork.userName
If NOT (FSO.FolderExists(Path + "\AppData\Roaming\Macromedia")) Then
FSO.CreateFolder(Path + "\AppData\Roaming\Macromedia")
End If
If NOT (FSO.FolderExists(Path + "\AppData\Roaming\Macromedia\Flash Player")) Then
' Delete this if you don't want the MsgBox to show
'MsgBox("Local folder doesn't exists, creating...")
' Create folder
'MsgBox("C:\" + splitString(2) + "\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client")
FSO.CreateFolder(Path + "\AppData\Roaming\Macromedia\Flash Player")
End If
If NOT (FSO.FolderExists(Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com")) Then
' Delete this if you don't want the MsgBox to show
'MsgBox("Local folder doesn't exists, creating...")
' Create folder
'MsgBox("C:\" + splitString(2) + "\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client\Profile")
FSO.CreateFolder(Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com")
End If
If NOT (FSO.FolderExists(Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin")) Then
' Delete this if you don't want the MsgBox to show
'MsgBox("Local folder doesn't exists, creating...")
' Create folder
'MsgBox("C:\" + splitString(2) + "\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client\Profile")
FSO.CreateFolder(Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin")
End If
If NOT (FSO.FolderExists(Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin")) Then
' Delete this if you don't want the MsgBox to show
'MsgBox("Local folder doesn't exists, creating...")
' Create folder
'MsgBox("C:\" + splitString(2) + "\ProgramData\Cisco\Cisco AnyConnect Secure Mobility Client\Profile")
FSO.CreateFolder(Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobeconnectaddin")
End If
'All folders created, if non-existent
'Check to see if the files already exists in the destination folder
If fso.FileExists(DestinationFile1) Then
'Check to see if the file is read-only
If Not fso.GetFile(DestinationFile1).Attributes And 1 Then
'The file exists and is not read-only. Safe to replace the file.
fso.CopyFile SourceFile1, DestinationPath, True
Else
'The file exists and is read-only.
'Remove the read-only attribute
fso.GetFile(DestinationFile1).Attributes = fso.GetFile(DestinationFile1).Attributes - 1
'Replace the file
fso.CopyFile SourceFile1, DestinationPath, True
'Reapply the read-only attribute
fso.GetFile(DestinationFile1).Attributes = fso.GetFile(DestinationFile1).Attributes + 1
End If
Else
'The file does not exist in the destination folder. Safe to copy file to this folder.
fso.CopyFile SourceFile1, DestinationPath, True
End If
If fso.FileExists(DestinationFile2) Then
'Check to see if the file is read-only
If Not fso.GetFile(DestinationFile2).Attributes And 1 Then
'The file exists and is not read-only. Safe to replace the file.
fso.CopyFile SourceFile2, DestinationPath, True
Else
'The file exists and is read-only.
'Remove the read-only attribute
fso.GetFile(DestinationFile2).Attributes = fso.GetFile(DestinationFile2).Attributes - 1
'Replace the file
fso.CopyFile SourceFile2, DestinationPath, True
'Reapply the read-only attribute
fso.GetFile(DestinationFile2).Attributes = fso.GetFile(DestinationFile2).Attributes + 1
End If
Else
'The file does not exist in the destination folder. Safe to copy file to this folder.
fso.CopyFile SourceFile2, DestinationPath, True
End If
Set fso = Nothing
Теперь, когда я бегу, я получаю сообщение об ошибке: Bad имя файла или номер.
Очки отметить:
- Структура папок будет создаваться в порядке
- копия ошибки для задач CopyFile.
Есть что-то с переменной «путь». С целевыми файлами вы всегда добавляете C: \ users в начале, но позже, когда папки создаются, вы этого не делаете. Вы не сказали, откуда оно взялось, поэтому я не уверен на 100%, но я думаю, что при создании папок последнее правильное использование. – Syberdoor
Ошибка, возникающая с помощью строки: fso.CopyFile SourceFile1, DestinationPath, True (строка: 103, символ: 9) Ошибка: Плохое имя или номер файла. Оба файла помещаются в тот же каталог, что и скрипт, и имена отмечены абсолютно правильно. Пожалуйста помоги. – Souvik
Оператор конкатенации строк - это амперсанд ('&'), а не '+'. Еще лучше, используйте ['fso.BuildPath()'] (https://msdn.microsoft.com/en-us/library/z0z2z1zt%28v=vs.84%29.aspx), чтобы создать свои пути. 'WScript.Echo' пути, чтобы увидеть, что вы создаете. –