Accessing collections with FSO

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Steve

    Accessing collections with FSO

    I have a folder object whose associated files collection I can iterate
    through using a "for each / next" loop to retrieve all the file names
    individually. I cannot however directly access the n'th item in the files
    collection? Here is my code so far;

    ' create FSO & folder objects
    Dim objFSO
    objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
    Dim objFld 'folder object &
    objFld = objFSO.GetFolde r(Server.MapPat h("/test"))

    ' now directly access file # 4 & return file name
    Return objFld.Files.It em(4).Name

    This code snippet gives me a "parameter is incorrect" on the "return" line.

    Any ideas? Thanks

    Steve


  • Wicksy

    #2
    Re: Accessing collections with FSO

    hiya...

    for starters i would use the My.Computer.Fil eSystem object, because the
    Scripting.FileS ystemObject is extremely slow in .NET.

    ' make a read-only collection:
    Dim files As ReadOnlyCollect ion(Of String)

    ' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of all
    files in a folder.
    ' you can change the 2nd and 3rd parameters to suit:
    files = My.Computer.Fil eSystem.GetFile s( folderpath,
    FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)

    ' Display the FIFTH item:
    msgbox files.item(4)


    HTH



    "Steve" <sjtnet@hotmail .com> wrote in message
    news:%235LGcSox FHA.3772@TK2MSF TNGP11.phx.gbl. ..[color=blue]
    >I have a folder object whose associated files collection I can iterate
    >through using a "for each / next" loop to retrieve all the file names
    >individually . I cannot however directly access the n'th item in the files
    >collection? Here is my code so far;
    >
    > ' create FSO & folder objects
    > Dim objFSO
    > objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
    > Dim objFld 'folder object &
    > objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
    >
    > ' now directly access file # 4 & return file name
    > Return objFld.Files.It em(4).Name
    >
    > This code snippet gives me a "parameter is incorrect" on the "return"
    > line.
    >
    > Any ideas? Thanks
    >
    > Steve
    >
    >[/color]


    Comment

    • Dragon

      #3
      Re: Accessing collections with FSO

      Hi Steve,

      It seems that Files.Item() property requires name of the file passed,
      bot it's number, e.g.:

      ~
      MessageBox.Show (fso.GetFolder( "C:\").Files.It em("BOOTLOG.TXT ").Path)
      ~

      Indeed, what is file #4? The don't have any order.


      Also, I strongly advice you to use System.IO.Direc tory class for such
      kind of jobs.

      Hope this helps,
      Roman

      "Steve" <sjtnet@hotmail .com> ñîîáùèë/ñîîáùèëà â íîâîñòÿõ ñëåäóþùåå:
      news:#5LGcSoxFH A.3772@TK2MSFTN GP11.phx.gbl...[color=blue]
      > I have a folder object whose associated files collection I can iterate
      > through using a "for each / next" loop to retrieve all the file names
      > individually. I cannot however directly access the n'th item in the[/color]
      files[color=blue]
      > collection? Here is my code so far;
      >
      > ' create FSO & folder objects
      > Dim objFSO
      > objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
      > Dim objFld 'folder object &
      > objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
      >
      > ' now directly access file # 4 & return file name
      > Return objFld.Files.It em(4).Name
      >
      > This code snippet gives me a "parameter is incorrect" on the "return"[/color]
      line.[color=blue]
      >
      > Any ideas? Thanks
      >
      > Steve
      >
      >[/color]



      Comment

      • Steve

        #4
        Re: Accessing collections with FSO

        Hi, and thanks for the response & ideas.

        I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &

        your "files = My.Computer.... " assignment gives me the "Name 'my' is not
        declared" error.

        I probably should mention that I am trying to implement this functionality
        into a web control.

        Any other ideas? Thanks, Steve

        "Wicksy" <wicksee@nosp am-yahoo.com> wrote in message
        news:dhmab6$qn0 $1@news.freedom 2surf.net...[color=blue]
        > hiya...
        >
        > for starters i would use the My.Computer.Fil eSystem object, because the
        > Scripting.FileS ystemObject is extremely slow in .NET.
        >
        > ' make a read-only collection:
        > Dim files As ReadOnlyCollect ion(Of String)
        >
        > ' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
        > all files in a folder.
        > ' you can change the 2nd and 3rd parameters to suit:
        > files = My.Computer.Fil eSystem.GetFile s( folderpath,
        > FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)
        >
        > ' Display the FIFTH item:
        > msgbox files.item(4)
        >
        >
        > HTH
        >
        >
        >
        > "Steve" <sjtnet@hotmail .com> wrote in message
        > news:%235LGcSox FHA.3772@TK2MSF TNGP11.phx.gbl. ..[color=green]
        >>I have a folder object whose associated files collection I can iterate
        >>through using a "for each / next" loop to retrieve all the file names
        >>individuall y. I cannot however directly access the n'th item in the files
        >>collection? Here is my code so far;
        >>
        >> ' create FSO & folder objects
        >> Dim objFSO
        >> objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
        >> Dim objFld 'folder object &
        >> objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
        >>
        >> ' now directly access file # 4 & return file name
        >> Return objFld.Files.It em(4).Name
        >>
        >> This code snippet gives me a "parameter is incorrect" on the "return"
        >> line.
        >>
        >> Any ideas? Thanks
        >>
        >> Steve
        >>
        >>[/color]
        >
        >[/color]


        Comment

        • Wicksy

          #5
          Re: Accessing collections with FSO

          what version of .NET are you using??



          "Steve" <sjtnet@hotmail .com> wrote in message
          news:OlpSj38xFH A.2516@TK2MSFTN GP12.phx.gbl...[color=blue]
          > Hi, and thanks for the response & ideas.
          >
          > I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &
          >
          > your "files = My.Computer.... " assignment gives me the "Name 'my' is not
          > declared" error.
          >
          > I probably should mention that I am trying to implement this functionality
          > into a web control.
          >
          > Any other ideas? Thanks, Steve
          >
          > "Wicksy" <wicksee@nosp am-yahoo.com> wrote in message
          > news:dhmab6$qn0 $1@news.freedom 2surf.net...[color=green]
          >> hiya...
          >>
          >> for starters i would use the My.Computer.Fil eSystem object, because the
          >> Scripting.FileS ystemObject is extremely slow in .NET.
          >>
          >> ' make a read-only collection:
          >> Dim files As ReadOnlyCollect ion(Of String)
          >>
          >> ' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
          >> all files in a folder.
          >> ' you can change the 2nd and 3rd parameters to suit:
          >> files = My.Computer.Fil eSystem.GetFile s( folderpath,
          >> FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)
          >>
          >> ' Display the FIFTH item:
          >> msgbox files.item(4)
          >>
          >>
          >> HTH
          >>
          >>
          >>
          >> "Steve" <sjtnet@hotmail .com> wrote in message
          >> news:%235LGcSox FHA.3772@TK2MSF TNGP11.phx.gbl. ..[color=darkred]
          >>>I have a folder object whose associated files collection I can iterate
          >>>through using a "for each / next" loop to retrieve all the file names
          >>>individually . I cannot however directly access the n'th item in the files
          >>>collection ? Here is my code so far;
          >>>
          >>> ' create FSO & folder objects
          >>> Dim objFSO
          >>> objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
          >>> Dim objFld 'folder object &
          >>> objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
          >>>
          >>> ' now directly access file # 4 & return file name
          >>> Return objFld.Files.It em(4).Name
          >>>
          >>> This code snippet gives me a "parameter is incorrect" on the "return"
          >>> line.
          >>>
          >>> Any ideas? Thanks
          >>>
          >>> Steve
          >>>
          >>>[/color]
          >>
          >>[/color]
          >
          >[/color]


          Comment

          • Steve

            #6
            Re: Accessing collections with FSO

            ..Net version 1.1

            XP Pro with SP2

            "Wicksy" <wicksee@nosp am-yahoo.com> wrote in message
            news:dhrcc3$jgo $1@news.freedom 2surf.net...[color=blue]
            > what version of .NET are you using??
            >
            >
            >
            > "Steve" <sjtnet@hotmail .com> wrote in message
            > news:OlpSj38xFH A.2516@TK2MSFTN GP12.phx.gbl...[color=green]
            >> Hi, and thanks for the response & ideas.
            >>
            >> I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &
            >>
            >> your "files = My.Computer.... " assignment gives me the "Name 'my' is not
            >> declared" error.
            >>
            >> I probably should mention that I am trying to implement this
            >> functionality into a web control.
            >>
            >> Any other ideas? Thanks, Steve
            >>
            >> "Wicksy" <wicksee@nosp am-yahoo.com> wrote in message
            >> news:dhmab6$qn0 $1@news.freedom 2surf.net...[color=darkred]
            >>> hiya...
            >>>
            >>> for starters i would use the My.Computer.Fil eSystem object, because the
            >>> Scripting.FileS ystemObject is extremely slow in .NET.
            >>>
            >>> ' make a read-only collection:
            >>> Dim files As ReadOnlyCollect ion(Of String)
            >>>
            >>> ' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
            >>> all files in a folder.
            >>> ' you can change the 2nd and 3rd parameters to suit:
            >>> files = My.Computer.Fil eSystem.GetFile s( folderpath,
            >>> FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)
            >>>
            >>> ' Display the FIFTH item:
            >>> msgbox files.item(4)
            >>>
            >>>
            >>> HTH
            >>>
            >>>
            >>>
            >>> "Steve" <sjtnet@hotmail .com> wrote in message
            >>> news:%235LGcSox FHA.3772@TK2MSF TNGP11.phx.gbl. ..
            >>>>I have a folder object whose associated files collection I can iterate
            >>>>through using a "for each / next" loop to retrieve all the file names
            >>>>individuall y. I cannot however directly access the n'th item in the
            >>>>files collection? Here is my code so far;
            >>>>
            >>>> ' create FSO & folder objects
            >>>> Dim objFSO
            >>>> objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
            >>>> Dim objFld 'folder object &
            >>>> objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
            >>>>
            >>>> ' now directly access file # 4 & return file name
            >>>> Return objFld.Files.It em(4).Name
            >>>>
            >>>> This code snippet gives me a "parameter is incorrect" on the "return"
            >>>> line.
            >>>>
            >>>> Any ideas? Thanks
            >>>>
            >>>> Steve
            >>>>
            >>>>
            >>>
            >>>[/color]
            >>
            >>[/color]
            >
            >[/color]


            Comment

            • Wicksy

              #7
              Re: Accessing collections with FSO

              ah, the solution i gave works in .net 2.0

              "Steve" <sjtnet@hotmail .com> wrote in message
              news:Ot3JmoDyFH A.2992@TK2MSFTN GP11.phx.gbl...[color=blue]
              > .Net version 1.1
              >
              > XP Pro with SP2
              >
              > "Wicksy" <wicksee@nosp am-yahoo.com> wrote in message
              > news:dhrcc3$jgo $1@news.freedom 2surf.net...[color=green]
              >> what version of .NET are you using??
              >>
              >>
              >>
              >> "Steve" <sjtnet@hotmail .com> wrote in message
              >> news:OlpSj38xFH A.2516@TK2MSFTN GP12.phx.gbl...[color=darkred]
              >>> Hi, and thanks for the response & ideas.
              >>>
              >>> I seem only able to "Dim" my collections as "ReadOnlyCollec tionBase" &
              >>>
              >>> your "files = My.Computer.... " assignment gives me the "Name 'my' is not
              >>> declared" error.
              >>>
              >>> I probably should mention that I am trying to implement this
              >>> functionality into a web control.
              >>>
              >>> Any other ideas? Thanks, Steve
              >>>
              >>> "Wicksy" <wicksee@nosp am-yahoo.com> wrote in message
              >>> news:dhmab6$qn0 $1@news.freedom 2surf.net...
              >>>> hiya...
              >>>>
              >>>> for starters i would use the My.Computer.Fil eSystem object, because the
              >>>> Scripting.FileS ystemObject is extremely slow in .NET.
              >>>>
              >>>> ' make a read-only collection:
              >>>> Dim files As ReadOnlyCollect ion(Of String)
              >>>>
              >>>> ' use My.Computer.Fil eSystem.GetFile s to return a ReadOnlyCollect ion of
              >>>> all files in a folder.
              >>>> ' you can change the 2nd and 3rd parameters to suit:
              >>>> files = My.Computer.Fil eSystem.GetFile s( folderpath,
              >>>> FileIO.SearchOp tion.SearchAllS ubDirectories, anyWildcards)
              >>>>
              >>>> ' Display the FIFTH item:
              >>>> msgbox files.item(4)
              >>>>
              >>>>
              >>>> HTH
              >>>>
              >>>>
              >>>>
              >>>> "Steve" <sjtnet@hotmail .com> wrote in message
              >>>> news:%235LGcSox FHA.3772@TK2MSF TNGP11.phx.gbl. ..
              >>>>>I have a folder object whose associated files collection I can iterate
              >>>>>through using a "for each / next" loop to retrieve all the file names
              >>>>>individual ly. I cannot however directly access the n'th item in the
              >>>>>files collection? Here is my code so far;
              >>>>>
              >>>>> ' create FSO & folder objects
              >>>>> Dim objFSO
              >>>>> objFSO = Server.CreateOb ject("Scripting .FileSystemObje ct")
              >>>>> Dim objFld 'folder object &
              >>>>> objFld = objFSO.GetFolde r(Server.MapPat h("/test"))
              >>>>>
              >>>>> ' now directly access file # 4 & return file name
              >>>>> Return objFld.Files.It em(4).Name
              >>>>>
              >>>>> This code snippet gives me a "parameter is incorrect" on the "return"
              >>>>> line.
              >>>>>
              >>>>> Any ideas? Thanks
              >>>>>
              >>>>> Steve
              >>>>>
              >>>>>
              >>>>
              >>>>
              >>>
              >>>[/color]
              >>
              >>[/color]
              >
              >[/color]


              Comment

              Working...