Results 1 to 2 of 2

Thread: Looping

  1. #1
    Join Date
    Dec 1969

    Default Looping

    I am still learning the very basics. I&#039;ve searched a lot, but cant seem to find a good tutorial on looping. here&#039;s the deal.<BR><BR>I&#039;m using fso to determine the file size of files who&#039;s filenames are listed in a database. I can loop through the recordset and display all the records okay, but i can only seem to return the file size of the first record.<BR><BR>strFileName = Server.MapPath("../data/downloads/" & rs("FileName"))<BR><BR>Dim objFSO<BR>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR><BR>&#039;Determine if the file exists<BR>If objFSO.FileExists(strFileName) Then<BR><BR>&#039;Get a file object<BR>Dim objFile<BR>Set objFile = objFSO.GetFile(strFileName)<BR><BR>&#039;Get the file size<BR>Dim iFileSize<BR>iFileSize = objFile.Size<BR>Else<BR>End If<BR><BR>strFileName comes from a field in my db. How do I loop this until EOF?

  2. #2
    Join Date
    Dec 1969

    Default RE: Looping

    &#062; I can loop through the recordset and display all the records okay,<BR><BR>So why didn&#039;t you show the code where you do that?<BR><BR>And why do you do<BR> Else<BR> End If<BR>If you don&#039;t have anything to put in the ELSE branch, just leave out the ELSE.<BR><BR>Oh, what the heck...let&#039;s give it a try ...<BR><BR>&#060;%<BR>Dim objFSO<BR>&#039; get the FSO only ONE time!<BR>Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR><BR>Dim basePath<BR>basePath = Server.MapPath("../data/downloads/")<BR><BR>Do Until RS.EOF<BR> strFileName = rs("FileName")<BR> fullPath = basePath & strFileName<BR><BR> &#039;Determine if the file exists<BR> If objFSO.FileExists(fullPath) Then<BR> &#039;Get a file object<BR> Dim objFile<BR> Set objFile = objFSO.GetFile(fullPath)<BR> &#039;Get the file size<BR> Dim iFileSize<BR> iFileSize = objFile.Size<BR> <BR> &#039; report it?<BR> Response.Write "File " & strFileName & " is " & iFileSize & " bytes&#060;br/&#062;"<BR> End If<BR> RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>

Posting Permissions

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