File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Traverse DOS/UNIX diretories - print members Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Traverse DOS/UNIX diretories - print members" Watch "Traverse DOS/UNIX diretories - print members" New topic
Author

Traverse DOS/UNIX diretories - print members

bob connolly
Ranch Hand

Joined: Mar 10, 2004
Posts: 204
Hello!

Does anyone know of a tool or java class that will allow me to traverse down to the sub-directory levels and print out certain files like, *.java, *.xml, *.jsp ect?

Thanks very much!

bc
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

If you use at the File API you should be able to traverse a diretory strucrure.

HINT: use 'listFiles()', 'isDirectory()' and 'isFile()' to traverse the diretory structure.

Rene
[ May 13, 2005: Message edited by: Rene Larsen ]

Regards, Rene Larsen
Dropbox Invite
bob connolly
Ranch Hand

Joined: Mar 10, 2004
Posts: 204
Thanks Rene!

Your right, it works great!

I don't think i could have done this with any other language in such a short time, love it!

Also Rene, i'm looking for a tool that will help me analyze a pretty large Java system, to at least produce a hierachy chart of classes, do you know of such a tool please?

Thanks again Rene!

import java.io.*;
import java.util.*;

public class r
{
public static void main(String[] args)
{
ArrayList ar = getFiles(new File(args[0]));

Object [] oa = ar.toArray();

for (int i=0;i<oa.length;i++)
{
String file_name = new String(oa[i].toString());
file_name = file_name.substring(1);
file_name = new String("/home/kennelly/JSF"+file_name);
if (file_name.indexOf(".java")>0)
{
System.out.println(file_name+"------------------------------------------------");
try
{
BufferedReader textReader = new BufferedReader(new FileReader(file_name));
String line = new String();
while ((line = textReader.readLine()) != null )
{
System.out.println(line);
}
textReader.close();
}
catch (IOException e) {System.out.println(e);}
}
}
}
public static ArrayList getFiles(File parent)
{
ArrayList current = new ArrayList();

if(parent!=null)
{
File[] files = parent.listFiles();

if(files!=null)
{
for(int i=0;i<files.length;i++)
{
if(files[i].isDirectory())
current.addAll(getFiles(files[i]));
else
current.add(files[i]);
}
}
}
return current;
}
}
bob connolly
Ranch Hand

Joined: Mar 10, 2004
Posts: 204
Hi again Rene!

I would like to do a "page break" whenever a new file name begins and i've tried the "\r" characters at the end of the file line, copied the output to notepad file for printing on an HP, but the "\r" doesn't seem to work!

Is there any way to cause a "page break" this way?

Thanks again Rene!
bc

for (int i=0;i<oa.length;i++)
{
String file_name = new String(oa[i].toString());
file_name = file_name.substring(1);
file_name = new String("/home/test/JSF"+file_name);
if (file_name.indexOf(".java")>0)
{
System.out.println(file_name+"\r"); <<<<<<<<<<<<<<<<<<<<<
try
{
BufferedReader textReader = new BufferedReader(new FileReader(file_name));
String line = new String();
while ((line = textReader.readLine()) != null )
{
System.out.println(line);
}
textReader.close();
}
catch (IOException e) {System.out.println(e);}
}
}
}
bob connolly
Ranch Hand

Joined: Mar 10, 2004
Posts: 204
ok got it, "\f" , form feed does the trick, thanks anyway Rene!

bc
Rene Larsen
Ranch Hand

Joined: Oct 12, 2001
Posts: 1179

Originally posted by bob connolly:
ok got it, "\f" , form feed does the trick, thanks anyway Rene!

bc


I normaly use "\n" (new line) when i want to start on a new line ;-)

Rene
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Traverse DOS/UNIX diretories - print members