Results 1 to 8 of 8
Thread: find file with * on the path
- 07-05-2009, 03:21 PM #1
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
find file with * on the path
Hello
I need to check if there are files in path that in the the format that might contain "*" .
( for example
/tmp/*/1224/*.doc
mathing path can be /tmp/dir1/1224/abcd.doc
in linux is very simple ( set files = "/tmp/*/1224/*.doc" )
How can I do it in java without start searching for "*" and buliding lops?Last edited by itaipee; 07-05-2009 at 05:06 PM.
- 07-05-2009, 04:22 PM #2
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
- 07-05-2009, 05:06 PM #3
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
I dont know how to do it in java ( can do this search in in perl and unix shell but not in java )Is this an assignment of yours or, just want to share with others?
I don't have so much knowledge in java to start share ..If you want to share your knowledge on thisLast edited by itaipee; 07-05-2009 at 05:08 PM.
- 07-06-2009, 05:11 AM #4
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Normally in Windows * sign stand for all the possibilities.
If the path is something like this, dir/* what you have to do is search all the folders in dir
In Java you can do this in several ways.
Java Code:import java.io.File; class ListFiles { File directoryOfFiles = new File("dir"); // directoryOfFiles contains relevant object if(directoryOfFiles.isDirectory() { // Validate for directoty String filenames[] = directoryOfFiles.list(); //make array of filenames. } }
- 07-06-2009, 09:39 AM #5
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
I tried to avoid lops. otherwise search like that for example will require 3 lops
/database/*/info/*/*.txt
the line to search is not known in the compliation phase so I don't know I much lop to make
- 07-06-2009, 10:11 AM #6
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
Actually you no need to use any loops. As I shown in the above example, in one File constructor you can do all.
- 07-06-2009, 03:41 PM #7
Member
- Join Date
- Dec 2008
- Posts
- 99
- Rep Power
- 0
you totally miss my point
File.list will be good for looking of all files in directory.
My case is that the directory is unknown - but the file itself is known
let say you have under the /database/ , you have 100 directory with integer name ( /database/1/ /database/2/... ) and under each one there might be ( with emphasis on might be ) sub dir called target. on the target dir , there might be file called target_file.
I want to look for /database/*/target/target_file.
I'm working to sovle it now with lops , and its ugly solution.
- 07-08-2009, 08:05 AM #8
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18
In simple words, you know the target and you want to find the dir path, am I correct?
Similar Threads
-
Cannot find class in same path.
By ribbs2521 in forum New To JavaReplies: 4Last Post: 05-07-2009, 05:25 PM -
How to set Image file path
By anil.bharadia in forum AWT / SwingReplies: 1Last Post: 01-28-2009, 09:10 PM -
file path
By Arsench in forum New To JavaReplies: 7Last Post: 10-30-2008, 05:39 AM -
Regular expression for file path
By ravian in forum New To JavaReplies: 3Last Post: 01-25-2008, 08:24 PM -
to find the workspace path at runtime to write the file
By Gnanam in forum Advanced JavaReplies: 5Last Post: 07-31-2007, 04:22 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks