vbscript错误800A004C

时间:2010-06-22 12:45:33

标签: vbscript

我需要在文件夹 C:\ Documents and Settings \ All Users \ Application中创建名为“ listfile.txt ”的文本文件 Data \ netapp \ system 所以我做了以下vbscript来实现

Const CommonAppData = &H23&  ' the second & denotes a long integer '
Const OSCPATH = "\netapp\system"
Dim fso, MyFile

Set objShell  = CreateObject("Shell.Application")
Set objFolder = objShell.Namespace(CommonAppData)

Set objFolderItem = objFolder.Self

'MsgBox objFolderItem.Name & ": " & objFolderItem.Path


Set fso = CreateObject("Scripting.FileSystemObject")
Set MyFile = fso.CreateTextFile("objFolderItem.Path & OSCPATH\listfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

但是找不到提示路径的投掷错误

** Windows脚本宿主

脚本:C:\ Documents and Settings \ puthuprf \ Desktop \ test.vbs 行:15 Char:1 错误:找不到路径 代码:800A004C

来源:Microsoft VBScript运行时错误


--------------------------- **

1 个答案:

答案 0 :(得分:1)

脚本中的这一行不正确:

Set MyFile = fso.CreateTextFile("objFolderItem.Path & OSCPATH\listfile.txt", True)

要将变量和对象属性插入到字符串中,需要使用&运算符将它们连接起来,如下所示:

Set MyFile = fso.CreateTextFile(objFolderItem.Path & OSCPATH & "\listfile.txt", True)


请注意,建议使用BuildPath方法组合路径的多个部分,因为它使您无需手动添加必要的路径分隔符(\):

strFileName = fso.BuildPath(objFolderItem.Path, OSCPATH)
strFileName = fso.BuildPath(strFileName, "listfile.txt")

Set MyFile = fso.CreateTextFile(strFileName, True)