vbscript 错误 800A004C [英] vbscript error 800A004C

查看:56
本文介绍了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)

这篇关于vbscript 错误 800A004C的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆