# Opening file in java without knowing the name

This topic is 4075 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi, Is there any way to open say an arbitrary log file in java without knowing the whole name? For example, if the file is named log234293847Lbuild.256, I want to open all of the files(perhaps store them in a list) with "build.256" at the end. I don't care about the long number before it. In perl, there is a function called glob that does just that -> @myfiles = glob("*.log"); Is there any way to do this? Thanks

##### Share on other sites
You can use Jakarta ORO which provides Perl style helper classes. This includes org.apache.oro.io.GlobFilenameFilter; which gives you functionality similar to Perl's glob.

##### Share on other sites

I will check this out.

##### Share on other sites
I dug out some code I got for such an occasion. Plus, I wanted to see if I could get the code tags to work. It's not fancy and probobly not robust enough, but it should work.

   File dir = new File(aDirectoryName);      String[] children = dir.list();      if (children == null)      {         // Either dir does not exist or is not a directory      }      else      {         for (int i = 0; i < children.length; i++)         {            // Get filename of file or directory            String filename = children;            // if ( filename.endswith("build.log") )            aList.add(filename);         }      }

##### Share on other sites
Yes I could try getting the directory and doing it that way, however, what I'm attempting to do is read an xml log file on another machine. I'm using CruiseControl for continuous integration of a project and it will write log files every time a build is made. The problem is, for a failed build it will not append a build label to the end of the log file name. And these log files are accessable at a URL to parse like "http://hostaddress:8080/buildresults/project/log23423423423Lbuild.234". But there is no way to get that long number after /log(LongNumber)Lbuild.234. So I need to see if I can parse the file without knowing that number, or simply just open the file without knowing the number, i just know about the build number at the end.

##### Share on other sites
Also I'm using the dashboard for Cruise Control which I think runs on the jetty web server, so I don't need to make any socket connections in my own code.

1. 1
2. 2
Rutin
18
3. 3
4. 4
5. 5
frob
12

• 9
• 22
• 15
• 9
• 17
• ### Forum Statistics

• Total Topics
632608
• Total Posts
3007396

×

## Important Information

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!