?
Solved

how can i identify some folders and ignore others?

Posted on 2003-03-03
9
Medium Priority
?
174 Views
Last Modified: 2010-04-01
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 );
%>

0
Comment
Question by:matthewblest2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 2
9 Comments
 
LVL 14

Expert Comment

by:kennethxu
ID: 8060085
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.
0
 

Author Comment

by:matthewblest2
ID: 8083206
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
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8085551
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] );
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 14

Expert Comment

by:kennethxu
ID: 8085557
sorry, the above won't work. are you sure that you only have 2 levels?
0
 
LVL 14

Accepted Solution

by:
kennethxu earned 100 total points
ID: 8085611
<%@page import="java.io.*, javax.servlet.jsp.JspWriter" %>
<%!
int countFile( JspWriter out, File dir ) throws IOException {
   File[] files = dir.listFiles();
   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 + " files" );
   out.println( ".</ul>" );
   return count;
}

int listSubDir( JspWriter out, File dir ) throws IOException {
   File[] files = dir.listFiles();
   int subCount = 0;
   for( int ii=0, end=files.length; ii < end; ii++ ) {
        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 += countFile( out, files[ii] );
        }
   }
   return subCount;
}

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 += listSubDir( out, files[ii] );
     }
   return subCount;
}
%>
<%
   String path = application.getRealPath( "/" );
   File dir = new File( path );
   listDir( out, dir );
%>

0
 

Author Comment

by:matthewblest2
ID: 8086767
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.
0
 
LVL 14

Expert Comment

by:kennethxu
ID: 8088655
ok, then have you tried my code and is there any problem?
0
 
LVL 35

Expert Comment

by:girionis
ID: 10040908
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
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Active Directory can easily get cluttered with unused service, user and computer accounts. In this article, I will show you the way I like to implement ADCleanup..
In today's business world, data is more important than ever for informing marketing campaigns. Accessing and using data, however, may not come naturally to some creative marketing professionals. Here are four tips for adapting to wield data for insi…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses
Course of the Month10 days, 16 hours left to enroll

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question