vbscript 错误 800A004C
我需要在文件夹 C:\Documents and Settings\All Users\Application 中创建一个名为listfile.txt"的文本文件Data\netapp\system 所以我做了以下 vbscript 来实现
i need to create a text file named "listfile.txt" in the folder C:\Documents and Settings\All Users\Application Data\netapp\system so i did the following vbscript to acheive that
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
但未找到提及路径的抛出错误
but its throwing errors mentioning path is not found
脚本:C:\Documents and Settings\puthuprf\Desktop\test.vbs线路:15字符:1错误:找不到路径代码:800A004C
Script: C:\Documents and Settings\puthuprf\Desktop\test.vbs Line: 15 Char: 1 Error: Path not found Code: 800A004C
好的
---------------------------**
OK
---------------------------**
脚本中的这一行不正确:
This line in your script is incorrect:
Set MyFile = fso.CreateTextFile("objFolderItem.Path & OSCPATH\listfile.txt", True)
要将变量和对象属性插入字符串,您需要使用 &
运算符将它们连接起来,如下所示:
To insert variables and object properties into a string, you need to concatenate them using the &
operator, like this:
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)