Create page from folder contents

Results 1 to 2 of 2

Thread: Create page from folder contents

  1. #1
    Join Date
    Dec 1969

    Default Create page from folder contents

    I am trying to work out how to create a news page for a site that would be dynamically updated depending on the contents of a folder. The folder inquestion would contain txt files each with a story contained within. I wanted the code to iterate through each file resident in the folder, open it and read lines of text into certain variables used for displaying on the page.<BR> <BR>I tried some code as follows: -<BR> <BR>&#060;%@Language="VBScript"%&#062;<BR>&#060;%< BR> Option Explicit<BR> Dim strFilePathInfo, strFilePhysicalPath<BR> <BR> strFilePathInfo = Request.ServerVariables("PATH_INFO")<BR> strFilePhysicalPath = Server.MapPath(strFilePathInfo)<BR> <BR> Dim objFSO, objFile, objFolder, objFolderContents<BR> <BR> set objFSO = CreateObject("Scripting.FileSystemObject")<BR> set objFile = objFSO.GetFile(strFilePhysicalPath)<BR> Set objFolder = objFile.ParentFolder<BR> Set objFolderContents = objFolder.Files<BR> <BR> Const ForReading = 1, ForWriting = 2, ForAppending = 8<BR> Const TristateUseDefault = -2<BR> <BR> Dim objFileTextStream, strLink, strHead, strStory<BR> set objFileTextStream = objFile.OpenAsTextStream(ForReading, TristateUseDefault)<BR> <BR> For each objFileItem in objFolderContents<BR> strLink = objFileTextStream.ReadLine<BR> strHead = objFileTextStream.ReadLine<BR> Do While objFileTextStream &#060;&#062; True<BR> strLine = objFileTextStream.ReadLine<BR> strStory = strStory & strLine<BR> Loop<BR> Response.Write strTitle & "<BR>"<BR> Response.Write strHead & "<BR>"<BR> Response.Write strStory & "<BR>"<BR> Next<BR> <BR> objFileTextStream.Close<BR> objFSO.Close<BR>%&#062; <BR> <BR>When I run this code with a couple of text files in the folder the page just takes forever to load and I wondered if I was in an infinte loop or something.<BR> <BR>Regards,<BR> <BR>Gavin

  2. #2
    Join Date
    Dec 1969

    Default readall

    While not being an expert on this, I would suggest to use readall and not readLine and split the first 2 lines.<BR>That would take one loop ...out of the loop...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts