我正在使用以下 vbscript,但似乎无法复制文件。如果我使用绝对文件路径,它就可以工作。
如何在 Windows 7 中设置这些路径以使其起作用。
Const DestinationFile = "%UserProfile%\Desktop\plrplus.dotm"
Const SourceFile = "%UserProfile%\Desktop\PLRPlus\plrplus.dotm"
Set fso = CreateObject("Scripting.FileSystemObject")
'Check to see if the file already exists in the destination folder
If fso.FileExists(DestinationFile) Then
'Check to see if the file is read-only
If Not fso.GetFile(DestinationFile).Attributes And 1 Then
'The file exists and is not read-only. Safe to replace the file.
fso.CopyFile SourceFile, "%UserProfile%\Desktop\plrplus.dotm" True
Else
'The file exists and is read-only.
'Remove the read-only attribute
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes - 1
'Replace the file
fso.CopyFile SourceFile, "%UserProfile%\Desktop\plrplus.dotm", True
'Reapply the read-only attribute
fso.GetFile(DestinationFile).Attributes = fso.GetFile(DestinationFile).Attributes + 1
End If
Else
'The file does not exist in the destination folder. Safe to copy file to this folder.
fso.CopyFile SourceFile, "%UserProfile%\Desktop\plrplus.dotm", True
End If
Set fso = Nothing
答案1
根据 DavidPostill 的建议,这两种不同的东西都起作用了。
桌面是特殊文件夹,因此:
Set objShell = CreateObject( "WScript.Shell" )
objShell.SpecialFolders("Desktop")
对于用户中的其他文件夹,我们可以扩展环境字符串
Set objShell = CreateObject( "WScript.Shell" )
objShell.ExpandEnvironmentStrings("%APPDATA%")