I'm trying to create a line in VBS that will create a file path with the file name as a variable, but I'm getting a Permission Denied error.
This is what I have so far:
filename = WScript.Arguments.unnamed(0) 'this value is transfered from a batch file.
Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
Set xmlDoc = CreateObject("Microsoft.XMLDOM")
xmlDoc.Async = "False"
xmlDoc.Load ("C:\Users\c1921\Ayla_Data\XMLFile.xml")
Set colNodes = xmlDoc.SelectNodes _
("/properties/property/(name)")
For Each objNode In colNodes
strSource = "C:\Users\c1921\Ayla_Data\AylaDatapoints\" & filename & ".csv"
Dim fso, f
Set fso = WScript.CreateObject("Scripting.Filesystemobject")
Set f = fso.OpenTextFile(strSource, 2)
I've also added a msgbox(filename)
line to see what value I get and it is the correct value.
I've also tried something like this to see if it would help and it doesn't work either:
Set f = fso.OpenTextFile("C:\Users\c1921\Ayla_Data\AylaDatapoints\AC000N000004593.csv", 2)
This should be easy I don't know where I'm going wrong. Any help finding the right direction would be greatly appreciated.
I've also tried something like this (among other variations) if it's relevant:
Set f = fso.OpenTextFile("C:\Users\c1921\Ayla_Data\AylaDatapoints\" & Chr(34) & filename & Chr(34) & " " & ".csv", 2) & Chr(34)
Edit:
Tried making the file in VBs with this code:
strSource = "C:\Users\c1921\Ayla_Data\AylaDatapoints\" & filename & ".csv"
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objLogFile = objFSO.CreateTextFile(strSource, _
ForWriting, True)
objLogFile.Writeline
I still get Permission Denied run time error. The file is created but this is the only thing written in it:
Microsoft (R) Windows Script Host Version 5.8
Copyright (C) Microsoft Corporation. All rights reserved.