Results 1 to 6 of 6

Thread: how to open file with certain name

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Unhappy how to open file with certain name

    how can i open file that have certain name what i mean that i am interest in certain file that have hallo in it name however it is the total name of file or not
    how can i make that

  2. #2
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: how to open file with certain name

    If I quite understood your question, and I think nobody can (Explain)
    Code:
        if (file.getName().indexOf("hallo") != -1) {
          //Your code here
        }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: how to open file with certain name

    thank you for your reply
    i will try to explain more
    what i mean i make could that is search for certain name to open it
    but i donot know all the name of file but part of it i want code that could find all file that have that certain part
    thank you again

  4. #4
    Frenzied Member System_Error's Avatar
    Join Date
    Apr 2004
    Posts
    1,111

    Re: how to open file with certain name

    Quote Originally Posted by shereen
    thank you for your reply
    i will try to explain more
    what i mean i make could that is search for certain name to open it
    but i donot know all the name of file but part of it i want code that could find all file that have that certain part
    thank you again
    That's exactly what CJ showed you. The indexOf method looks for a piece of a string and returns -1 if the search string does not contain it.

    This is exactly what your looking for:

    Code:
    if (file.getName().indexOf("hallo") != -1) {
          //Your code here
        }
    Which is what he posted.

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Mar 2006
    Posts
    23

    Re: how to open file with certain name

    thank you very much but when i creat file like
    flie f=new file("c:/................")
    and write
    file.getname();
    it give me the last name of file in path and that isnot what i want
    say that the path is c:/document............./input
    and i want to make search on the files that input folder have
    acoording to certain part of name

  6. #6
    Arabic Poster ComputerJy's Avatar
    Join Date
    Nov 2005
    Location
    Happily misplaced
    Posts
    2,513

    Re: how to open file with certain name

    Code:
      public static void main (String args[]) {
        File f = new File("C:/") ;
        f.list(new FilenameFilter()
        {
          public boolean accept (File dir, String name) {
            return name.indexOf("hallo") != -1 ;
          }
        }) ;
      }
    "I'm not normally a praying man, but if you're up there, save me... Superman!" - Homer Simpson
    My Blog

Posting Permissions

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



Click Here to Expand Forum to Full Width