ASP/VBS List folders

Discussion in 'ASP General' started by Excel User, Sep 22, 2009.

  1. Excel User

    Excel User Guest

    Hi,

    I have the following script which lists all the folder names from
    'mainfolder'

    ListFolderContents(Server.MapPath("/mainfolder"))

    sub ListFolderContents(path)

    dim fs, folder

    set fs = CreateObject("Scripting.FileSystemObject")
    set folder = fs.GetFolder(path)

    Response.Write(folder.Name & "<br>")

    for each item in folder.SubFolders
    ListFolderContents(item.Path)
    next

    end sub

    but I would like to just list the first set of sub folders not the folders
    within these sub folders i.e. if I had the following directory structure

    mainfolder
    - folder 1
    - sub folder 1
    - folder 2
    - sub folder 2a
    - sub folder 2b
    - folder 3


    so I would only like to list the folder names with 'mainfolder' but not
    their sub-folders

    i.e.
    folder 1
    folder 2
    folder 3

    Thanks for any help!
     
    Excel User, Sep 22, 2009
    #1
    1. Advertising

  2. Excel User

    Bob Barrows Guest

    Excel User wrote:
    > Hi,
    >
    > I have the following script which lists all the folder names from
    > 'mainfolder'
    >
    > ListFolderContents(Server.MapPath("/mainfolder"))
    >
    > sub ListFolderContents(path)
    >
    > dim fs, folder
    >
    > set fs = CreateObject("Scripting.FileSystemObject")
    > set folder = fs.GetFolder(path)
    >
    > Response.Write(folder.Name & "<br>")
    >
    > for each item in folder.SubFolders
    > Response.Write(folder.Name & "<br>")
    > next
    >
    > end sub
    >
    > but I would like to just list the first set of sub folders not the
    > folders within these sub folders i.e. if I had the following
    > directory structure


    Replace the recursive call to the sub with a statement to write the
    subfolder name to Response. See above

    --
    HTH,
    Bob Barrows
     
    Bob Barrows, Sep 22, 2009
    #2
    1. Advertising

  3. Excel User

    Excel User Guest

    Bob, thanks for the reply but changing this just repeats the folder name
    several times i.e.

    mainfolder
    mainfolder
    mainfolder
    mainfolder

    any ideas?

    Thanks

    "Bob Barrows" <> wrote in message
    news:#...
    > Excel User wrote:
    >> Hi,
    >>
    >> I have the following script which lists all the folder names from
    >> 'mainfolder'
    >>
    >> ListFolderContents(Server.MapPath("/mainfolder"))
    >>
    >> sub ListFolderContents(path)
    >>
    >> dim fs, folder
    >>
    >> set fs = CreateObject("Scripting.FileSystemObject")
    >> set folder = fs.GetFolder(path)
    >>
    >> Response.Write(folder.Name & "<br>")
    >>
    >> for each item in folder.SubFolders
    >> Response.Write(folder.Name & "<br>")
    >> next
    >>
    >> end sub
    >>
    >> but I would like to just list the first set of sub folders not the
    >> folders within these sub folders i.e. if I had the following
    >> directory structure

    >
    > Replace the recursive call to the sub with a statement to write the
    > subfolder name to Response. See above
    >
    > --
    > HTH,
    > Bob Barrows
    >
    >
     
    Excel User, Sep 22, 2009
    #3
  4. Excel User

    Excel User Guest

    Bob,

    Don't worry - I've found the error - all sorted.

    Thanks again!

    "Bob Barrows" <> wrote in message
    news:#...
    > Excel User wrote:
    >> Hi,
    >>
    >> I have the following script which lists all the folder names from
    >> 'mainfolder'
    >>
    >> ListFolderContents(Server.MapPath("/mainfolder"))
    >>
    >> sub ListFolderContents(path)
    >>
    >> dim fs, folder
    >>
    >> set fs = CreateObject("Scripting.FileSystemObject")
    >> set folder = fs.GetFolder(path)
    >>
    >> Response.Write(folder.Name & "<br>")
    >>
    >> for each item in folder.SubFolders
    >> Response.Write(folder.Name & "<br>")
    >> next
    >>
    >> end sub
    >>
    >> but I would like to just list the first set of sub folders not the
    >> folders within these sub folders i.e. if I had the following
    >> directory structure

    >
    > Replace the recursive call to the sub with a statement to write the
    > subfolder name to Response. See above
    >
    > --
    > HTH,
    > Bob Barrows
    >
    >
     
    Excel User, Sep 22, 2009
    #4
  5. Excel User

    Bob Barrows Guest

    Well, I was somewhat hoping that you would pick up on what needed to be done
    .... and I now see that you did. Well done.


    Excel User wrote:
    > Bob, thanks for the reply but changing this just repeats the folder
    > name several times i.e.
    >
    > mainfolder
    > mainfolder
    > mainfolder
    > mainfolder
    >
    > any ideas?
    >
    > Thanks
    >
    > "Bob Barrows" <> wrote in message
    > news:#...
    >> Excel User wrote:
    >>> Hi,
    >>>
    >>> I have the following script which lists all the folder names from
    >>> 'mainfolder'
    >>>
    >>> ListFolderContents(Server.MapPath("/mainfolder"))
    >>>
    >>> sub ListFolderContents(path)
    >>>
    >>> dim fs, folder
    >>>
    >>> set fs = CreateObject("Scripting.FileSystemObject")
    >>> set folder = fs.GetFolder(path)
    >>>
    >>> Response.Write(folder.Name & "<br>")
    >>>
    >>> for each item in folder.SubFolders
    >>> Response.Write(folder.Name & "<br>")
    >>> next
    >>>
    >>> end sub
    >>>
    >>> but I would like to just list the first set of sub folders not the
    >>> folders within these sub folders i.e. if I had the following
    >>> directory structure

    >>
    >> Replace the recursive call to the sub with a statement to write the
    >> subfolder name to Response. See above
    >>
    >> --
    >> HTH,
    >> Bob Barrows


    --
    Microsoft MVP - ASP/ASP.NET - 2004-2007
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"
     
    Bob Barrows, Sep 22, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Brad

    Running a VBS file from ASP.NET

    Brad, Aug 28, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    526
  2. Alex
    Replies:
    1
    Views:
    2,624
    Alvin Bruney [MVP]
    Feb 16, 2004
  3. =?Utf-8?B?RGFuQw==?=

    Running Xcacls.vbs on ASP.net page fails

    =?Utf-8?B?RGFuQw==?=, Nov 15, 2005, in forum: ASP .Net
    Replies:
    0
    Views:
    720
    =?Utf-8?B?RGFuQw==?=
    Nov 15, 2005
  4. Nigel

    ASP.Net run VBS function

    Nigel, Aug 10, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    415
    =?Utf-8?B?U2l2YSBN?=
    Aug 10, 2007
  5. mike

    fire a VBS from ASP.NET

    mike, Aug 21, 2007, in forum: ASP .Net
    Replies:
    4
    Views:
    357
Loading...

Share This Page