Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Function which will give the names of all items in a folder [duplicate]

Tags:

java

function

Here's what I have to do, but I have no idea where to start:

Write a program that allows you to browse images (gif, jpg) from the specified directory. Pictures are subsequently shown in the window, as follows:

  • a) the catalog and the time interval between image (in seconds) is determined at the start of the program on the basis of information from the file,
  • b) images are shown in their original sizes,
  • c) adjust the image to the frame

I know the very basic question, but just getting started with Java. Is there some sort of function, which will give me the names of all items in a folder?

like image 937
Daniel Zawadzki Avatar asked May 12 '13 18:05

Daniel Zawadzki


People also ask

How to list all file names from a folder and sub-folders?

List all file names from a folder and sub-folders into a worksheet with a powerful feature. 1. Open Excel, Click Kutools Plus > Import / Export > Filename List…, see screenshot: 2. In the Filename List dialog box,do the following operations: (1.) Click button to specify the folder which contains the ...

How do I list the file names in a worksheet?

Below are the steps to use this function in a worksheet: In any cell, enter the folder address of the folder from which you want to list the file names. In the cell where you want the list, enter the following formula (I am entering it in cell A3): =IFERROR(INDEX(GetFileNames($A$1),ROW()-2),"")

How to list files of following folder in worksheet in Excel?

Supposing you need to list files of following folder in worksheet, see screenshot: 1. Go to copy the path of the folder ( Folder Test) in Explorer. For example, the path of this folder is: C:\Users\AddinTestWin10\Desktop\Folder Test. 2.

How to get a list of files and folders from a path?

We get a list of all files and folders present in the “data” directory. In this example, we passed a relative path but you can also pass an absolute path and get its contents as well. If you only want to get a list of files and not the directories, you can use the os.path.isfile () function which checks whether a given path is a file or not.


2 Answers

If you want to have File Objects for all files within a Directory, use:

new File("path/to/directory").listFiles();

If you instead just want the names use

new File("path/to/directory").list();
like image 121
Angelo Fuchs Avatar answered Oct 14 '22 04:10

Angelo Fuchs


If you want only the image files, you can use File.listFiles( FileFilter filter ):

 File[] files = new File( myPath ).listFiles( 
    new FileFilter() {
       boolean accept(File pathname) {
          String path = pathname.getPath();
          return ( path.endsWith(".gif") 
              || path.endsWith(".jpg")
              || ... );
       }
    });
like image 39
Andy Thomas Avatar answered Oct 14 '22 03:10

Andy Thomas