Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Listing folders+sub folders

  • 14-10-2004 07:03AM
    #1
    Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭


    Hi,
    Is there any way to get a printable list of all the folders in a certain archive.

    Just say I have a folder for projects by students for example and in the root folder its like this

    Aimee White
    Andrew Flynn
    Andy Whelan


    and so on and so on

    and then in each persons folder it would have a folder of the project:

    Aimee White:
    Stalin
    Hitler
    Industrial Revolution


    Is there any way to get a printable list so it would be like this:

    Aimee White
    Stalin
    Hitler
    Industrial Revolution
    Andrew Flynn
    Bronze Age
    Ancient Egypt
    Andrew Whelan
    WW1
    WW2
    etc etc
    etc
    etc

    I'd just like the folder names and I'd like to be able to edit the page so its not just filling up the left hand side of the page, I'd like to be able to squeeze it into as few pages as possible.

    Thank you!


Comments

  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Hey Cormie,

    This is definitely do-able, but it depends on a few things and would require some coding. First off, you're going to find this a lot easier to do if you have unix or a variant (i.e. Linux) or (my preference) perl.

    If you're running windows, I'm not sure that you can do this in a batch file, I certainly wouldn't know how (there are other dos geeks browsing this forum though, they might be able to help you). Unix shell scripts are very powerful and could do this handy enough.

    Basically, what you want to do is:
    check for directory,
    cd into directory,
    list only directories,
    cd ..
    repeat

    If you have perl on your machine (type perl -v at a command prompt) and no idea what the hell I'm rattling on about I'll stick a little script together for you.

    <edit> just noticed the word "archive" at the top there. Do you mean like a Zip file? If so, it's still doable, just a bit more of a pain. </edit>


  • Registered Users, Registered Users 2 Posts: 27,517 ✭✭✭✭GreeBo


    something simple like (in DOS)
    dir *. /s
    will give you all the folders under all the folders in root
    you will have to tidy it up to get the display you want.... easier to do in unix variant


  • Registered Users, Registered Users 2 Posts: 14,318 ✭✭✭✭Raam


    if you are using windows, then extract all the files (if they are in a zip file, not sure from your post).
    Then go to a command prompt and navigate to the folder which contains all the other folders that you want to list. Then type...

    tree /a > folder_list.txt

    this will build something like this...
    [HTML]
    C:.
    +---uguide
    | \---images
    \---appdev
    \---sample
    +---web
    | \---images
    +---src
    \---etc
    [/HTML]
    and will store it in the file folder_list.txt
    Does that help?
    KR


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    thanks for tips

    It's not a Zip archive don't worry, just plain folders:)

    Ok, How do I nav through DOS?

    I've figured how to get from C:documents and settings back to C:

    but now can't get back to C:Doc+Set

    What do I press to go somewhere and all that?
    Thanks


  • Registered Users, Registered Users 2 Posts: 14,318 ✭✭✭✭Raam


    Cormie,
    click this
    Then save the DOSHERE.INF file to your desktop.
    Right click that file and select 'install'
    now, when you right click any folder you will see a 'command prompt here' option. Click that and hey presto, a dos box will open in that folder!

    KR


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Thanks allot,

    now I tried that and all I got in the text file was something like what you have there, nothing to do with what was in the folder

    ok, so just say the folder is here

    C:\Documents and Settings\-\Desktop\Archive

    how do I list all folders+subfolders in that folder?

    Do I do the command prompt on that folder so I have:

    C:\Documents and Settings\-\Desktop\Archive>_

    On the dos screen? Then what?

    Thanks!


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Aha... think I got it:) thanks to everyone!


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    This is a long shot, but is there any way to highlight the main folders in bold?
    As in Andrews folder?


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    You'd need to change the document type to something that supports bold (likely HTML). That definitely requires programming. :)


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    and I'm guessing since I didn't even know how to nav to a folder, this is a far cry off from my capabilities? hehe.


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Go on then. You've twisted my arm.....

    At the bottom of this post is a bunch of perl. Select it with your mouse, right click, select copy. open notepad, select paste. Save that as "treenav.pl".

    Next go to here to download a copy of perl. Install this.

    To run the script open up a dos prompt (you're now a dab hand at this). Type:

    perl C:\scriptdirectory\treenav.pl C:\directory\you\want\output\on\

    (replace C:\scriptdirectory\treenav.pl with the directory that you saved to and replace C:\directory\you\want\output\on\ with well...it says it all)

    It will output in a nice html file called "directory_list.html". It only goes down one directory level, so if you need more than that, let me know and I'll make it recursive (fancy programmer talk).

    If you have trouble, shout.

    (perl geeks, don't bother giving me grief about my script. It works.)

    <EDIT>put in code tags for nice indentation</EDIT>



    use strict;
    
    if (! -d $ARGV[0])
    {
        die "usage: perl treenav.pl <directory>\n";
    }
    
    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";
    
    print FILE "<html>\n<head>\n</head>\n<body>\n";
    
    my $startdir = $ARGV[0];
    
    #get the list of files in the specified directory into an array
    opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
    my @files_in_dir = readdir CMDLINEDIR;
    closedir CMDLINEDIR;
    
    foreach my $file (@files_in_dir)
    {
        #get only directories:
        if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
        {
            print FILE "<b>$file</b><br>\n";
            
            opendir SUBDIR, ($startdir . '/' . $file) or die "Couldn't access $file. Check that it is readable and try again.\n";
            my @files_in_subdir = readdir SUBDIR;
            closedir SUBDIR;
            
            my $at_least_one_subdir = 0;
            
            foreach my $subdir_file (@files_in_subdir)
            {
                if (-d ($startdir . '/' . $file . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
                {
                    if (!$at_least_one_subdir)
                    {
                        $at_least_one_subdir = 1;
                        print FILE "<ul>\n";
                    }
                    
                    print FILE "<li>$subdir_file<br></li>\n";
                }
            }
            
            if ($at_least_one_subdir)
            {
                print FILE "</ul><br>\n";
            }
            
        }
    }
    
    print FILE "</body></html>\n";
    close FILE;
    __END__
    


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    GREAT! It worked!!! I'm very impressed with myself actually! haha.

    Just one thing, I would like there to be no spaces like:

    Aimee White
    Stalin
    Hitler
    Industrial Revolution
    Andrew Flynn
    Bronze Age
    Ancient Egypt
    Andrew Whelan
    WW1
    WW2

    Instead of the way it has come out:

    Aimee White

    Stalin
    Hitler
    Industrial Revolution


    Andrew Flynn

    Bronze Age
    Ancient Egypt


    Andrew Whelan

    WW1
    WW2



    I'm guessing it can be done by deleting stuff in the above pl file but I don't know what to get rid of. Once I know this it will be perfect:) thank you very much indeed! very nice of you!


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    cormie wrote:
    GREAT! It worked!!! I'm very impressed with myself actually! haha.

    :) and so you should be.

    ok...here's the updated version. I removed the bullet points and lines in between. It works the same way as the last one.
    use strict;
    
    if (! -d $ARGV[0])
    {
        die "usage: perl treenav.pl <directory>\n";
    }
    
    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";
    
    print FILE "<html>\n<head>\n</head>\n<body>\n";
    
    my $startdir = $ARGV[0];
    
    #get the list of files in the specified directory into an array
    opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
    my @files_in_dir = readdir CMDLINEDIR;
    closedir CMDLINEDIR;
    
    foreach my $file (@files_in_dir)
    {
        #get only directories:
        if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
        {
            print FILE "<b>$file</b><br>\n";
            
            opendir SUBDIR, ($startdir . '/' . $file) or die "Couldn't access $file. Check that it is readable and try again.\n";
            my @files_in_subdir = readdir SUBDIR;
            closedir SUBDIR;
            
            foreach my $subdir_file (@files_in_subdir)
            {
                if (-d ($startdir . '/' . $file . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
                {
                     print FILE "$subdir_file<br>\n";
                }
            }
            
        }
    }
    
    print FILE "</body></html>\n";
    close FILE;
    __END__
    


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Sorry my mistake...
    I actually wanted the bullet points on the non bold bits!

    Once this is done it will be perfect and I wont bug you anymore:) thanks for your efforts!


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Ok, no probs. Here ya go.
    use strict;
    
    if (! -d $ARGV[0])
    {
        die "usage: perl treenav.pl <directory>\n";
    }
    
    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";
    
    print FILE "<html>\n<head>\n</head>\n<body>\n";
    
    my $startdir = $ARGV[0];
    
    #get the list of files in the specified directory into an array
    opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
    my @files_in_dir = readdir CMDLINEDIR;
    closedir CMDLINEDIR;
    
    foreach my $file (@files_in_dir)
    {
        #get only directories:
        if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
        {
            print FILE "<b>$file</b>\n";
            
            opendir SUBDIR, ($startdir . '/' . $file) or die "Couldn't access $file. Check that it is readable and try again.\n";
            my @files_in_subdir = readdir SUBDIR;
            closedir SUBDIR;
            
            my $at_least_one_subdir = 0;
            
            foreach my $subdir_file (@files_in_subdir)
            {
                if (-d ($startdir . '/' . $file . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
                {
                    if (!$at_least_one_subdir)
                    {
                        $at_least_one_subdir = 1;
                        print FILE "<ul>\n";
                    }
                    
                    print FILE "<li>$subdir_file</li>\n";
                }
            }
            
            if ($at_least_one_subdir)
            {
                print FILE "</ul>\n";
            }
            
        }
    }
    
    print FILE "</body></html>\n";
    close FILE;
    __END__
    


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Haha,
    I actually wanted to bullets without spaces. But hey presto, I had a little look at the different scripts and I fixed it with this:)

    use strict;

    if (! -d $ARGV[0])
    {
    die "usage: perl treenav.pl <directory>\n";
    }

    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";

    print FILE "<html>\n<head>\n</head>\n<body>\n";

    my $startdir = $ARGV[0];

    #get the list of files in the specified directory into an array
    opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
    my @files_in_dir = readdir CMDLINEDIR;
    closedir CMDLINEDIR;

    foreach my $file (@files_in_dir)
    {
    #get only directories:
    if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
    {
    print FILE "<b>$file</b><br>\n";

    opendir SUBDIR, ($startdir . '/' . $file) or die "Couldn't access $file. Check that it is readable and try again.\n";
    my @files_in_subdir = readdir SUBDIR;
    closedir SUBDIR;

    foreach my $subdir_file (@files_in_subdir)
    {
    if (-d ($startdir . '/' . $file . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
    {
    print FILE "<li>$subdir_file<br></li>\n";
    }
    }

    }
    }

    print FILE "</body></html>\n";
    close FILE;
    __END__


    Thanks for all your help! Very kind of you, I may even attempt to try out the reputation crap for ya!thanks


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    cormie wrote:
    Haha,
    I actually wanted to bullets without spaces. But hey presto, I had a little look at the different scripts and I fixed it with this:)

    :D Welcome to the wonderful world of programming :)
    cormie wrote:
    Thanks for all your help! Very kind of you, I may even attempt to try out the reputation crap for ya!thanks

    No problem. Glad to help. :)


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    cormie wrote:
    Haha,
    I actually wanted to bullets without spaces. But hey presto, I had a little look at the different scripts and I fixed it with this:)

    use strict;

    if (! -d $ARGV[0])
    {
    die "usage: perl treenav.pl <directory>\n";
    }

    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";

    print FILE "<html>\n<head>\n</head>\n<body>\n";

    my $startdir = $ARGV[0];

    #get the list of files in the specified directory into an array
    opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
    my @files_in_dir = readdir CMDLINEDIR;
    closedir CMDLINEDIR;

    foreach my $file (@files_in_dir)
    {
    #get only directories:
    if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
    {
    print FILE "<b>$file</b><br>\n";

    opendir SUBDIR, ($startdir . '/' . $file) or die "Couldn't access $file. Check that it is readable and try again.\n";
    my @files_in_subdir = readdir SUBDIR;
    closedir SUBDIR;

    foreach my $subdir_file (@files_in_subdir)
    {
    if (-d ($startdir . '/' . $file . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
    {
    print FILE "<li>$subdir_file<br></li>\n";
    }
    }

    }
    }

    print FILE "</body></html>\n";
    close FILE;
    __END__


    Thanks for all your help! Very kind of you, I may even attempt to try out the reputation crap for ya!thanks


    Me again, I just noticed that it only lists the folder+sub, any chance of adding in the next level of folder if any to the format above? and the next? just to get all FOLDER names:) thanks


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    here goes....

    This puppy's recursive, so it'll work for any number of subdirectories. I was just lazy the last time :)
     use strict;
     
     if (! -d $ARGV[0])
     {
         die "usage: perl treenav.pl <directory>\n";
     }
     
    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";
     
     print FILE "<html>\n<head>\n</head>\n<body>\n";
     
     my $startdir = $ARGV[0];
     
     #get the list of files in the specified directory into an array
     opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
     my @files_in_dir = readdir CMDLINEDIR;
     closedir CMDLINEDIR;
     
     foreach my $file (@files_in_dir)
     {
         #get only directories:
         if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
         {
             print FILE "<b>$file</b><br>\n";
     
             parse_directory_tree($startdir . '/' . $file)
         }
     }
     
     print FILE "</body></html>\n";
     close FILE;
     
     sub parse_directory_tree
     {
     
         my $dir_to_parse = shift;
         opendir DIR, ($dir_to_parse) or die "Couldn't access $dir_to_parse. Check that it is readable and try again.\n";
         my @files_in_subdir = readdir DIR;
         closedir DIR;
     
         foreach my $subdir_file (@files_in_subdir)
         {
             if (-d ($dir_to_parse . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
             {
                 print FILE "<li>$subdir_file<br></li>\n";
                 parse_directory_tree($dir_to_parse . '/' . $subdir_file);
             }
         }
     
     
     }
     
     __END__
    


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Hey thats great thanks allot!
    but if there is any way to do it like so:

    Folder 1
    -A
    --apple
    -B
    -C
    --Cookies
    --Cream
    ---Whipped
    ----Low Fat
    ----Full
    --Celery
    -D

    if you could use - instead of bullet marks because I cannot copy the bullet marks when I copy the text to a word/text document.

    Thanks allot!

    by the way, your inbox for pms is full!


  • Advertisement
  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Jaysus....you don't ask for much :p

    It'll be tomorrow. I'm banjaxed and my noodle is melted. Far too melted for recursion and such like. :)


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Haha thanks allot, you've been great, the above request will definitely be the last!


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Ok, here we go.....
    use strict;
    
    my $num_minuses = 0;
    
    if (! -d $ARGV[0])
    {
        die "usage: perl treenav.pl <directory>\n";
    }
    
    open FILE, "> directory_list.html" or die "couldn't open directory_list.html for writing. Check that file / directory is writeable and try again.\n";
    
    print FILE "<html>\n<head>\n</head>\n<body>\n";
    
    my $startdir = $ARGV[0];
    
    #get the list of files in the specified directory into an array
    opendir CMDLINEDIR, $startdir or die "could not access the directory specified\n";
    my @files_in_dir = readdir CMDLINEDIR;
    closedir CMDLINEDIR;
    
    foreach my $file (@files_in_dir)
    {
        #get only directories:
        if (-d ($startdir . '/' . $file) && $file ne '.' && $file ne '..')
        {
            print FILE "<b>$file</b><br>\n";
    
            parse_directory_tree($startdir . '/' . $file)
        }
    }
    
    print FILE "</body></html>\n";
    close FILE;
    
    sub parse_directory_tree
    {
    
        $num_minuses++;
    
        my $dir_to_parse = shift;
        opendir DIR, ($dir_to_parse) or die "Couldn't access $dir_to_parse. Check that it is readable and try again.\n";
        my @files_in_subdir = readdir DIR;
        closedir DIR;
    
        foreach my $subdir_file (@files_in_subdir)
        {
            if (-d ($dir_to_parse . '/' . $subdir_file) && $subdir_file ne '.' && $subdir_file ne '..')
            {
                print FILE "-" x $num_minuses . "$subdir_file<br>\n";
                parse_directory_tree($dir_to_parse . '/' . $subdir_file);
            }
        }
        
        $num_minuses--;
    
    }
    
    __END__
    

    Enjoy. :)


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Brilliant! Great! Amazing!
    Perfect.
    Thank you very much! Much appreciated. Thanks for all your continual help.
    :):)


  • Closed Accounts Posts: 2,698 ✭✭✭IrishMike


    Khannie you are some hero for that ill tell ya.
    Fair play.


  • Registered Users, Registered Users 2 Posts: 20,859 ✭✭✭✭cormie


    Heres to Khannie!Good rep him folks!


  • Registered Users, Registered Users 2 Posts: 1,711 ✭✭✭Dr. Dre


    IrishMike wrote:
    Khannie you are some hero for that ill tell ya.
    Fair play.


    Absolutely.
    Above and beyond the call of duty there.
    Kudos.


  • Registered Users, Registered Users 2 Posts: 37,485 ✭✭✭✭Khannie


    Aw shucks. :o

    Thanks lads. :)


Advertisement