for each file

Results 1 to 3 of 3

Thread: for each file

  1. #1
    Join Date
    Dec 1969

    Default for each file

    I am trying to do a simple routine in which I access the files in a specified directory, however I would like to display only .xml files. What argument would I use to do this?<BR><BR>thanks-jen<BR><BR>code-<BR><BR>Function ExamineFolders(ByRef objFolder,ByVal intLevel)<BR> Dim Folder, File<BR> For each File in objFolder.Files<BR> &#039;If objFS.FileExists(Server.MapPath("directory")) then<BR> Response.Write "&#060;a href=&#039;directory" & File.Name & "&#039;&#062;" & File.Name & "&#060;/a&#062;" & "<BR>"<BR> &#039;End If<BR> Next<BR>End Function<BR>&#039; Determines which folder to display contents of <BR>Dim objFS, objRootFolder, strVRoot<BR>strVRoot=Server.MapPath("directory")<B R>Set objFS=Server.CreateObject("Scripting.FileSystemObj ect")<BR>Set objRootFolder=objFS.GetFolder(strVRoot)<BR>Examine Folders objRootFolder,1<BR>Set objRootFolder = Nothing<BR>Set objFS = Nothing

  2. #2
    Join Date
    Dec 1969

    Default RE: for each file

    You could conditionally check the name of the file and make sure the last four characters are ".xml" and only show those such files:<BR><BR>For each File in objFolder.Files<BR> If UCase(Right(File.Name, 4)) = ".XML" then<BR> &#039; ... dealing with an XML file ...<BR> Else<BR> &#039; ... dealing with something else ...<BR> End If<BR>Next<BR><BR>Hope this helps. Check the technical docs for more info:<BR>

  3. #3
    Join Date
    Dec 1969

    Default You can also...

    ...use the .type property of the file...<BR><BR>&#060;%<BR>For each File in objFolder.Files<BR>&nbsp; &nbsp; If File.Type = "???" Then then<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; ... dealing with an XML file ...<BR>&nbsp; &nbsp; Else<BR>&nbsp; &nbsp; &nbsp; &nbsp; &#039; ... dealing with something else ...<BR>&nbsp; &nbsp; End If<BR>Next<BR>%&#062;<BR><BR>Dunno what the .type is for an XML file, but easy enough to test it one time and find out.<BR><BR>Minor advantage in doing this: When a given "type" can be represented by more than one extension, you only need one test.<BR><BR>Examples: ".jpg" and ".jpeg" would have the same .Type. As would ".html" and ".htm". <BR><BR>[ I dunno why I put my two cents in on this one...maybe just to show that, yet again, there is more than one way to solve a given programming problem. ]<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