Link to home
Start Free TrialLog in
Avatar of matthewblest2
matthewblest2

asked on

how can i identify some folders and ignore others?

Following on from my previous question of counting files and folders, i need to isolate particular folder names and how many file are within, such as foldername/number of files has this many items, second folder has this many. thanks

here is the previous code i am working with:

<%@page import="java.io.*, javax.servlet.jsp.JspWriter" %>
<%!
int listDir( JspWriter out, File dir ) throws IOException {
    File[] files = dir.listFiles();
    int subCount = 0;
    for( int ii=0, end=files.length; ii < end; ii++ )
         if( files[ii].isDirectory() ) subCount += listDir( out, files[ii] );
    int count = 0;
    out.println( dir.getPath() );
    out.println( "<ul>" );
    for( int ii=0, end=files.length; ii < end; ii++ ) {
         if( files[ii].isFile() ) {
              out.println( "<li>"  + files[ii].getName() + "</li>" );
              count++;
         }
    }
    out.print( "<p>total: " + (count+subCount) + " files" );
    if( subCount > 0 ) out.print(", " + count + " in this dir, " + subCount +" in subdirs" );
    out.println( ".</ul>" );
    return subCount + count;
}
%>
<%
    String path = application.getRealPath( "/" );
    File dir = new File( path );
    listDir( out, dir );
%>

Avatar of kennethxu
kennethxu

not sure what exactly you are looking for, but if you want to ignore a folder, say WEB-INF, you can do this by:
change
if( files[ii].isDirectory() ) subCount += listDir( out, files[ii] );
to
if( files[ii].isDirectory() && !files[ii].getName().equals( "WEB-INF" ) ) subCount += listDir( out, files[ii] );

if I didn't get you, please give some example. thanks.
Avatar of matthewblest2

ASKER

what i'd really like is to be able to identify 5 folders, count how many files there are in them and present the results in a table, so in one website there are at least 80 sub webs, each subweb would need to be identified and the five folders within that subweb listed with the number of files in. if i can do this from one jsp page and add up the results of each column at the end of the table that would be great, thanks

Top Root of Website/
website_one:
has four files in folder A
36 in folder b
45 in folder c
12 in folder d
46 in folder e

website_two:
has four files in folder A
26 in folder b
55 in folder c
126 in folder d
6 in folder e
String name = files[ii].getName();
if( files[ii].isDirectory() && (name.equals("A") || name.equals("b") || name.equals("c") || name.equals("d") || name.equals("e")) ) subCount += listDir( out, files[ii] );
sorry, the above won't work. are you sure that you only have 2 levels?
ASKER CERTIFIED SOLUTION
Avatar of kennethxu
kennethxu

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
its a very unsually done web, there is never more than this structure to it, it was restricted in scope to keep things easy for non web people to edit:

top_websitefolder>

topic_webfolder>
folder_one
folder_two
folder_three
etc.

topic_webfolder_two>
folder_one
folder_two
etc.

these 'folders' never have any folders within them, just web pages.
ok, then have you tried my code and is there any problem?
Avatar of girionis
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points to kennethxu

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

girionis
EE Cleanup Volunteer