Results 1 to 8 of 8
  1. #1
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default 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.

  2. #2
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Quote Originally Posted by itaipee View Post
    A challange: I need to check if there are files in path that in the the format that might contain "*" .
    Is this an assignment of yours or, just want to share with others? If you want to share your knowledge on this, this is not the correct sub-forum. Let me know I'll move this thread.

  3. #3
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    Is this an assignment of yours or, just want to share with others?
    I dont know how to do it in java ( can do this search in in perl and unix shell but not in java )

    If you want to share your knowledge on this
    I don't have so much knowledge in java to start share ..
    Last edited by itaipee; 07-05-2009 at 05:08 PM.

  4. #4
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    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.
          }
    }

  5. #5
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    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

  6. #6
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

    Default

    Actually you no need to use any loops. As I shown in the above example, in one File constructor you can do all.

  7. #7
    itaipee is offline Member
    Join Date
    Dec 2008
    Posts
    99
    Rep Power
    0

    Default

    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.

  8. #8
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,372
    Blog Entries
    1
    Rep Power
    20

Similar Threads

  1. Cannot find class in same path.
    By ribbs2521 in forum New To Java
    Replies: 4
    Last Post: 05-07-2009, 05:25 PM
  2. How to set Image file path
    By anil.bharadia in forum AWT / Swing
    Replies: 1
    Last Post: 01-28-2009, 09:10 PM
  3. file path
    By Arsench in forum New To Java
    Replies: 7
    Last Post: 10-30-2008, 05:39 AM
  4. Regular expression for file path
    By ravian in forum New To Java
    Replies: 3
    Last Post: 01-25-2008, 08:24 PM
  5. Replies: 5
    Last Post: 07-31-2007, 04:22 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •