Results 1 to 7 of 7

Thread: Directories

  1. #1
    KevMeistr is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default Directories

    Hi..

    I'm really not sure if this topic is advanced or beginner stuff but here goes..

    I have a directory on my computer that is in the same directory as the java files that I save to disk..in that directory are all kinds of .htm files..is there any way of "seeing" inside the directory and checking whether a file is of the form that I specify.

    Sorry, if this doesn't make sense..

  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
    19

  3. #3
    sukatoa's Avatar
    sukatoa is offline Senior Member
    Join Date
    Jan 2008
    Location
    Cebu City, Philippines
    Posts
    556
    Rep Power
    7

    Default

    I may get all the file names of that directory(Form of array), and check if the extension is an htm file or not....

    You may implement a method that receives a file name and returns true if the given filename is a htm file...

    If i got what you meant...
    freedom exists in the world of ideas

  4. #4
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Default File class

    Java io package has a class called File - it behaves remarkably like a file as we know it. One can do:
    import java.io.File;
    File aFile = new File(".");//

    and that will get you the current directory. We then can do
    String[] arrayOfFiles = aFile.list();//

    And thus get an array with all the filenames in it just as one would see in windowed gui

    See:

    java.sun.com/j2se/1.3/docs/api/java/io/File.html

    Often, if one knew how to ask the question - you could answer the question.

  5. #5
    KevMeistr is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    Hi again..

    Yeah I used the File class from io but I want to pass a filter to list the files as the type of filter I specified..

    i.e. I pass 2 strings; directory name (easy to convert to File) and filter (having trouble converting to FilenameFilter)

    I have the filter as "E.*\.htm"..so I want to create an array of all .htm files that have this type of name format..

    Thanks in advance.. the File class was really helpul

  6. #6
    KevMeistr is offline Member
    Join Date
    Jun 2008
    Posts
    4
    Rep Power
    0

    Default

    Yes, that's right..

    Just look at my previous post

  7. #7
    Nicholas Jordan's Avatar
    Nicholas Jordan is offline Senior Member
    Join Date
    Jun 2008
    Location
    Southwest
    Posts
    1,018
    Rep Power
    7

    Default

    I had trouble getting filename filter to work, after some reading I decided it was actually and interface. At that time I had just gained the ablility to write an interface, what one does is write a class declaring it implements the interface - then code the methods declared in the interface.

    At that point, it is accept(String filename) or some version of that: I would have to look at the docs. In that class, the method would look for htm or html. The String class has a search method, it returns minus one if the string does not contain what you are looking for. There is a way to have it look at the end of the string, but I would have to look it up for you.

    It is better if you make several attempts, then ask me when you are stuck. I can now look stuff up efficiently and seem to do well getting people unstuck - sometimes on api's I never heard of.

Similar Threads

  1. JSP getting list of directories
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 01-31-2008, 12:51 PM
  2. Replies: 8
    Last Post: 01-07-2008, 05:41 AM
  3. getting paths and directories
    By marco in forum Java Applets
    Replies: 3
    Last Post: 11-25-2007, 07:28 AM

Posting Permissions

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