tags:

views:

19

answers:

1

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

**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
---------------------------**

A: 

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)
Helen
thats great Helen,,its works fine,,i am new to vbscript thats why,Thanks you for your help
peter
peter why the downvote?
I__