Manipulating Folder objects' "Files" property

Results 1 to 4 of 4

Thread: Manipulating Folder objects' "Files" property

  1. #1
    Justin Bursch Guest

    Default Manipulating Folder objects' "Files" property

    I&#039;m really stumped on this one and would at least like some<BR>clarification if not a complete answer. Why can&#039;t I treat the<BR>Files collection for the Folder object like any other collection? <BR><BR>Here&#039;s the snippet of code I&#039;m using:<BR>------------------------------------------------<BR>Dim objFSO, objFile, objFolder, intCount<BR><BR> Set objFSO = Server.CreateObject("Scripting.FileSystemObject")< BR> Set objFolder = objFSO.GetFolder(Server.MapPath("forum/ariba_messages"))<BR><BR> For intCount = objFolder.Files.Count to 1 step -1<BR> set objFile = objFolder.Files(intCount)<BR> Response.Write "&#060;li&#062;&#060;font size=""2""&#062;&#060;a href=""forum/ariba_messages/" & objFile.Name & """ class=""blu""&#062;" & Replace(objFile.Name,"_"," ",1) & "&#060;/a&#062;&#060;/font&#062;&#060;/li&#062;"<BR> Next<BR><BR> Set objFolder = Nothing<BR> Set objFSO = Nothing<BR>-------------------------------------------------------------<BR>In the actual code, everything that is supposed to all be on<BR>one line IS (things just got butchered when I copied over to<BR>post this message). <BR><BR>Now, here is the Runtime error I get:<BR>--------------------------------------------<BR>Microsoft VBScript runtime error &#039;800a0005&#039; <BR><BR>Invalid procedure call or argument <BR><BR>/Epro/view_list.asp, line 69 <BR>--------------------------------------------<BR>What&#039;s the deal? If the objFolder.Files property is<BR>a collection of file objects, why can&#039;t I single one<BR>of them out by it&#039;s collection index number and put<BR>it into a new object (objFile, in this case)? It<BR>seems logical, but for whatever reason, it just<BR>won&#039;t work. I&#039;m sure there are other approaches to <BR>what I&#039;m trying to do, but I want to know why this <BR>one doesn&#039;t work. Thanks to all in advance.<BR><BR>Justin

  2. #2
    Tony Guest

    Default RE: Manipulating Folder objects'

    Iterate through the collection this way;<BR><BR><BR>&#039;------------------------------------------------ <BR>Dim objFSO, objFolder, objFiles, objFile <BR><BR> Set objFSO = Server.CreateObject("Scripting.FileSystemObject") <BR> Set objFolder = objFSO.GetFolder(Server.MapPath("forum/ariba_messages")) <BR> set objFiles = objFolder.Files<BR> <BR> For each objFile in objFiles<BR> Response.Write "&#060;li&#062;&#060;font size=""2""&#062;&#060;a href=""forum/ariba_messages/" & objFile.Name & """ class=""blu""&#062;" & Replace(objFile.Name,"_"," ",1) & "&#060;/a&#062;&#060;/font&#062;&#060;/li&#062;" <BR> Next <BR><BR> Set objFile = Nothing<BR> Set objFolder = Nothing <BR> Set objFSO = Nothing <BR>&#039;-------------------------------------------------------------

  3. #3
    Justin Bursch Guest

    Default RE: Manipulating Folder objects'

    Hi Tony.<BR><BR>Thanks for your reply. You are right on, but I already knew<BR>how to iterate in this fashion (I&#039;ve done it many times before).<BR>My question was really more about why one CAN&#039;T do it the way<BR>I was attempting to. The reason I wanted to try and do it this way was because I want to iterate BACKWARDS through the collection of file objects WITHOUT using an array (why create<BR>a copy of the data and consume memory if you don&#039;t have to?!).<BR>It seemed like it would be simple enough using the normal<BR>access method for collections (index number), but I guess<BR>it doesn&#039;t work if your collection consists of file or folder objects. Or does it? I still don&#039;t know for sure. Anyway, I<BR>was able to achieve the desired effect with an array, but I&#039;m<BR>still wondering about my first approach.<BR>Anybody?<BR><BR>Justin

  4. #4
    Richard A. Lowe Guest

    Default RE: Manipulating Folder objects'

    As far as I can see, the key field of Files.Item(key) does not accept an integer to dereference an individual File object.<BR><BR>So this:<BR><BR>Set objFile = objFiles("somefile.txt") &#039; will work<BR>Set objFile = objFiles(1) &#039; will never work

Posting Permissions

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