Results 1 to 10 of 10
  1. #1
    RafalD is offline Member
    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Default Load all file in child directories

    Hi!

    I have problem. I must load to program all file(graphics) in folder, and in all child folder. I know how load, problem is load all images without having their names.
    For example:

    Folder:
    - image1.gif
    - image2.gif
    - image3.gif
    - folder_child1:
    - - image4.gif
    - folder_child2:
    - - image5.gif
    - - image6.gif
    - - child_folder_child2:
    - - - image7.gif
    - - - image8.gif
    I mean, program loaded all image 1,2,3,4,5,6,7,8.
    Number and folder names are unknown.

    You know how can i resolve problem?

    Greetings,
    Rafał

    PS: Sorry for my bad english.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,765
    Blog Entries
    7
    Rep Power
    21

    Default Re: Load all file in child directories

    Have a look at the File class; it can do what you want.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  3. #3
    RafalD is offline Member
    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Default Re: Load all file in child directories

    Ok, I make it.
    But now I have this problem:
    I need read only folders(directories) and graphist file(example only .gif).

    You know, how make it?

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Load all file in child directories

    You could use a FileFilter?
    Or use the predone FileNameExtensionFIlter, and the isDirectory() method on File?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    RafalD is offline Member
    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Default Re: Load all file in child directories

    I use:
    source.list(FilenameFilter.accept(source, ".gif"));
    And it return error.

  6. #6
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Load all file in child directories

    You don't fancy actually telling us the error, or do we have to guess?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  7. #7
    RafalD is offline Member
    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Default Re: Load all file in child directories

    It is example simple code:
    Java Code:
    import java.io.File;
    import java.io.FilenameFilter;
    
    public class lists {
    	public static void main(String[] args) {
    		String infile = "img/";
    		File source = new File(infile);
    		String[] files = source.list(FilenameFilter.accept(source, ".gif"));
    		for(int i=0;i<files.length;i++)
            {
    			System.out.println(files[i]);    
            }              
        }
    }
    And theye are errors:
    XML Code:
    Cannot make a static reference to the non-static method accept(File, String) from the type FilenameFilter	lists.java
    The method list(FilenameFilter) in the type File is not applicable for the arguments (boolean)

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Load all file in child directories

    You need to create a FilenameFilter object.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  9. #9
    RafalD is offline Member
    Join Date
    Dec 2012
    Posts
    16
    Rep Power
    0

    Default Re: Load all file in child directories

    When I create a object:
    Java Code:
    FilenameFilter filter = new FilenameFilter();
    It is error:
    Cannot intiantiate the type FilenameType

    When I don't initialize:
    Java Code:
    import java.io.File;
    import java.io.FilenameFilter;
     
    public class lists {
        public static void main(String[] args) {
            String infile = "img/";
            File source = new File(infile);
            FilenameFilter filter;
            String[] files = source.list(filter);
            for(int i=0;i<files.length;i++)
            {
                System.out.println(files[i]);    
            }              
        }
    }
    It is error:
    The local variable filter may not have been initialized

  10. #10
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,224
    Rep Power
    20

    Default Re: Load all file in child directories

    Please give the actual errors, not your typed in interpretation of them.

    FilenameFilter is an interface.
    You have to write the code for it.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

Similar Threads

  1. Replies: 15
    Last Post: 02-16-2012, 04:43 PM
  2. load pdf from jar file (help please)
    By 3ammary in forum Advanced Java
    Replies: 13
    Last Post: 07-29-2011, 09:23 PM
  3. Load RDF file
    By priyam_maheshwari in forum Advanced Java
    Replies: 2
    Last Post: 06-27-2011, 11:54 PM
  4. file load
    By myka in forum Advanced Java
    Replies: 1
    Last Post: 04-03-2010, 09:42 PM
  5. Backslash, File directories, and streams
    By rp181 in forum Advanced Java
    Replies: 4
    Last Post: 10-15-2009, 10:54 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
  •