Variables 将2个文件复制到当前用户配置文件的路径中
我正在尝试复制以下路径中的几个文件: C:\Users\username\AppData\Roaming\Macromedia\Flash Player\www.Macromedia.com\bin\adobeconnectaddin 我使用的是VBS,我使用的脚本如下:Variables 将2个文件复制到当前用户配置文件的路径中,variables,deployment,vbscript,file-copying,Variables,Deployment,Vbscript,File Copying,我正在尝试复制以下路径中的几个文件: C:\Users\username\AppData\Roaming\Macromedia\Flash Player\www.Macromedia.com\bin\adobeconnectaddin 我使用的是VBS,我使用的脚本如下: DestinationFile1 = ("C:\Users" + Path + "\AppData\Roaming\Macromedia\Flash Player\www.macromedia.com\bin\adobecon
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
现在,当我运行它时,我得到一个错误:错误的文件名或编号
注意事项:
在我看来,当您创建destinationFile1和destinationFile2时,您的路径似乎还没有设置好
您是否尝试过在这两个变量之前设置路径?您的变量“path”有问题。对于目标文件,您总是在开始时附加C:\users,但在创建文件夹后,您不会附加C:\users。你没有说它从哪里来,所以我不是100%确定,但我猜在创建文件夹时,后一个是正确的用法。出现的错误是:fso.CopyFile SourceFile1,DestinationPath,True(行:103,Char:9)。错误是:错误的文件名或编号。这两个文件都与脚本放在同一个目录中,并且名称标注完全正确。请提供帮助。字符串连接运算符是与(
&
),而不是+
。更好的方法是,使用创建路径WScript.Echo
查看路径以查看您正在创建的内容。谢谢,但是路径创建得很好。我同意这会使脚本变短,但是问题在于copyfile命令,而不是路径。即使我使用+而不是&我也会得到同样的错误。我试着这样做:DestinationPath=(“C:\Users”+path+“\AppData\Roaming\Macromedia\Flash Player\www.Macromedia.com\bin\adobeconnectaddin”)来回答JBP的问题:是的,它首先检查并创建完整的文件夹结构,然后尝试复制文件。是的,它首先检查并创建完整的文件夹结构,然后尝试复制文件。你能检查一下完整的脚本和帮助吗?我真的需要尽快开始。好的,我不完全确定,但是getfile.attribute应该返回一个值,1或0。正确的?如果是这种情况,那么如果不是fso.GetFile(DestinationFile1.Attributes)和1,那么似乎在问一些问题。我认为如果不是fso.GetFile(DestinationFile1.Attributes=1,那么应该是