A simple way to list/filter files

Here is a very simple and elegant way to list or filter the files in a given directory.

For this use the File.listFiles() method of java.io.File class.

The example below deletes all the files that end with the “.tmp” extension.

Below is the code sample:

Code sample to list/filter files within a directory

Code sample to list/filter files within a directory

There are some limitations that you need to be aware of:

1. This code will not recursively list/delete files.

2. It will also list the subfolder names (if any).

Advertisements
This entry was posted in Java and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s