January 17th, 2012, 07:01 AM
Frustrating OpenTextFile Permission Denied Error
I am writing what SHOULD be a simple piece of code to read selected contents of several XML files into a master XML file. I have ensured that each file is opened, read and closed but always on the second iteration, I have a permission denied error from the script. Code below:
I would appreciate any help as I cannot find anything that would explain this issue (especially as it runs perfectly on the first iteration).
If oFSO.FolderExists(strTempFolder) Then
Set oXML = oFSO.CreateTextFile (strXMLFile,1)
oXML.WriteLine "<?xml version=""1.0"" encoding=""iso-8859-1""?>"
set oFolder = oFSO.GetFolder(strTempFolder)
icount = 1
For each oFile in oFolder.Files
icount = icount + 1
set oFullFile = oFSO.OpenTextFile(strTempFolder & oFile.Name,1,False) 'This is the location of the error
strContents = oFullFile.ReadAll
aSection1 = split(strContents,"<header>")
aSection2 = split(aSection1(1),"</keys>")
oXML.WriteLine "<header>" & aSection2(0) & "</keys>"
set oFullFile = nothing