开发者

vbscript error 800A004C

开发者 https://www.devze.com 2023-01-04 13:37 出处:网络
i need to create a text file named \"listfile.txt\" in the folder C:\\Documents and Settings\\All Users\\Application

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("o开发者_运维知识库bjFolderItem.Path & OSCPATH\listfile.txt", True)
MyFile.WriteLine("This is a test.")
MyFile.Close

but its throwing errors mentioning path is not found

**Windows Script Host

Script: C:\Documents and Settings\puthuprf\Desktop\test.vbs Line: 15 Char: 1 Error: Path not found Code: 800A004C

Source: Microsoft VBScript runtime error

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)


Note that it is recommended to use the BuildPath method to combine multiple parts of the path, as it frees you from adding the necessary path separators (\) manually:

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

Set MyFile = fso.CreateTextFile(strFileName, True)
0

精彩评论

暂无评论...
验证码 换一张
取 消