Results 1 to 4 of 4

Thread: App to generate web page listing of sub-folders/files in selected directory?

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2006
    Posts
    41

    Smile App to generate web page listing of sub-folders/files in selected directory?

    Hello everybody,

    Having tried several utilities which generate a web page listing of a directory's contents I am am going to try and develop my own because those I downloaded were not as configurable as I would have wished.

    I'm trying to find my way around visual C# so I'm not looking for specific snippets of code, basically what I want is pointers as to what I'd need to do the following:

    1: Allow the user to select a target directory to scan.
    2: Allow the user to select an output directory for the generated web page.
    3: At the top of the generated web page there should be a list of the sub-folders found under the target directory, this list should be a set of hyperlinks to locations further down the same page listing the files found in each sub-folder.

    What control(s) will I need to do the scanning?

    Am I correct in assuming that the app should generate the html as it scans the directories and files or should it temporarily store the info and write the html later?

    Thanks for your help.

    Regards,

    The Thing.
    Using: VB.net + C#.net 2005 Express Editions + .Net Framework 2.0

    ~ Man Is The Warmest Place To Hide ~

  2. #2
    Member MasterEvilAce's Avatar
    Join Date
    Jul 2002
    Posts
    60

    Re: App to generate web page listing of sub-folders/files in selected directory?

    1) in the toolbox go under Dialogs and you'll find "Folder Browser Dialog".. Never used it, but openFile and save File i've used a lot, and they're SIMPLE.

    2) Save file dialog?


    For 3) It depends what you're needing to do. If you set it up right, if you loop through the files and write the web page at the same time, you're looping through stuff a lot less, so it'll be a lot faster. If you need to do any processing with the data, you're probably better off retrieving the data, then processing/saving it.

    I'm not sure of any control that'll automatically scan for you.. I don't think it would be helpful either, though. But what I do is
    string[] Directories = System.IO.Directory.GetDirectories(@"C:\Folder\");

    And then I loop through the Directories array and each instance holds the Folder name of a directory in C:\Folder\

    there's also a Directory.GetFiles if you need to retrieve files

  3. #3
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: App to generate web page listing of sub-folders/files in selected directory?

    It's a simple task. GetDirectories() will get you the directories you want. Creating the page is only a matter of creating a string of HTML with the 'dynamic' part being the listing of the files with the information you can retrieve for them, in a table/div set.

    However, having the directories as links is going to be tough. I am assuming you are using Windows Forms, so the links that those directories go to will serve no purpose as you have no 'target' that can anticipate and execute a scan of the specified folder.

    One way to do this would be to loop recursively through every folder and every subfolder of every folder, generating pages for those, and having the directory links on the HTML page link to the other generated pages.

  4. #4
    Member MasterEvilAce's Avatar
    Join Date
    Jul 2002
    Posts
    60

    Re: App to generate web page listing of sub-folders/files in selected directory?

    That's what I ended up doing for a recentl project. Basically what I did was I had a list of directories which holds pointers to a Directory class that has Directory.Name and Directory.Files[]

    .Files is a list of pointers to a specific instance of the File class which has File.Name, File.Directory, File.Size, etc. Whatever you need, really.

    I have a function that populates the directories and files.

    You run the function, sending it a folder path.. you GetDirectories and run through the directories on the folder path, for each directory you call the SAME function again, this time passing it the subfolder's path.

    You also add each of these directories to the primary DirectoryList. Directory.Name I made relative to the target path. So it would hold NewFolder \A
    if the target path was C:\ and it found a sub-folder NewFolder had a subfolder A.


    AFTER you loop through the directories, you then loop through the files (because you have to create the directories FIRST, before you loop through the files ).

    So then whenever you want to process everything you just run through the main Directory list, and you have all the folders + subfolders listed essentially like this

    C:\TargetPath\ -->

    NewFolder\A
    NewFolder\A\AA
    NewFolder\B
    NewFolder\C
    NewFolder\C\CC
    NewFolder\C\CCC

    and then of course each directory has a list of files inside, so the world is yours. If you want root files, essentially

    As far as the webpage stuff, you basically want to use #targets, right? So everything is on ONE page? You can either use the Directory name (IE: page.html#NewFolder-A-AA

    and create an anchor in the page to the list of files OR you can use the ID of the directory in the Directory List, since it'll always be unique, and a very short number.. ie: page.html#2 (the second folder in the example above, NewFolder\A\AA)

    blah blah blah, i'm bored. hope it helps

Posting Permissions

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



Click Here to Expand Forum to Full Width