• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to get file information of any folder?  RSS feed

 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have some files in one folder (config) like rb.properties, rb_en_us.properties, rb_fr.properties etc. My need is to count all the files (and get the file name) that are starting with rb. Please help me is there any method that look in to specified folder and do such filtering...

Thanks a lot.
[ June 08, 2005: Message edited by: rathi ji ]
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Look into the methods on the File object. You can create a File with a directory name and list all the files in the directory. There is an optional filter you could write to use regular expressions or any other pattern matching you like to select the files you want to count. Let us know if you get stuck using those.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Stan,

I did the same thing:

File dir = new File("config");
System.out.println(dir.getAbsolutePath());
String[] fileNames = dir.list();


But the issue is, When I run this code from main method it runs successfully and print absolute path perfectly but when I run it on server (It is a Web Application) it doesn't work and it print some different absolute path (probably where the server is installed)...

Please help me out anybody, what should I do?
Thanks a lot.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We have problems like that deploying on both Windows and Unix. Can you put the fully qualified path & name in configuration for each environment?
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
OK Stan,

This is the actual path of my config folder and when I run it through main method, it prints the same path.
C:\workspace\project\config

This is the path which gets printed, when I run it as a web application:
C:\Program Files\IBM\WebSphere Studio\Application Developer\v5.1.2\config

I am using WSAD and running application on Test Server of WSAD.

Please help me out...
Thanks.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!