如何在VBscript中使用变量user获取路径 [英] How to get a path with the variable user in VBscript
本文介绍了如何在VBscript中使用变量user获取路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要保存,移动和删除文件.但是,当我这样做时,我想让它将我的文件保存在登录用户的文档中.
I need to save, move and delete a file. But when I do that I want to let it save my files in the documents of the user that is logged on.
这是我的代码:
Set oWS = WScript.CreateObject("WScript.Shell")
' Get the %userprofile% in a variable, or else it won't be recognized
userProfile = oWS.ExpandEnvironmentStrings( "%userprofile%" )
objDoc.SaveAs("userprofile & "\Downloads\test.doc")
objWord.Quit
Const strFolder = "userprofile & "\Downloads\System Information\", strFile = "userprofile & "\Downloads\test.doc"
Const Overwrite = True
Dim oFSO
Set oFSO = CreateObject("Scripting.FileSystemObject")
If Not oFSO.FolderExists(strFolder) Then
oFSO.CreateFolder strFolder
End If
oFSO.CopyFile strFile, strFolder, Overwrite
oFSO.DeleteFile("userprofile & "\Downloads\test.doc")
推荐答案
在VBScript中,定义常量值时不能使用字符串连接(&
).请改用变量.
In VBScript, you can't use string concatenation (&
) when defining constant values. Use variables instead.
此外,在userprofile
变量名称前还有一个额外的引号.
Also, you have an extra quote before the userprofile
variable name.
这是固定代码:
...
objDoc.SaveAs(userprofile & "\Downloads\test.doc")
Dim strFolder : strFolder = userprofile & "\Downloads\System Information\"
Dim strFile : strFile = userprofile & "\Downloads\test.doc"
...
oFSO.DeleteFile(userprofile & "\Downloads\test.doc")
这篇关于如何在VBscript中使用变量user获取路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文