Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get a list of files???

Status
Not open for further replies.

mackey333

Technical User
May 10, 2001
563
US
I need to write a program to remove duplicate files in 2 directories...i have literally hundreds of duplicate files and i dont want to go through manually and compare them..i need to free hd space so i am trying to write a program to accomplish this...i need a method that can put files in a directory into an array and then a method to delete a file..i also take it that once i get the files in an array i can compare with them with == to determine if they are the same??..thanks for any help -Greg :-Q

flaga.gif
 
Look at the class File in java.io package.


File myDir = new File(<directory path>);

String[] myDirList = myDir.list();

This will return you a string array of all
file names in the directory.


Loop through the array of if you need to figure our
the file timestamp or size do as follows:



for ( i=0; i<myDirList.length; i++ )
{
File curFile = new File(myDirList);

Date lastMod = curFile.lastModified();
long size = curFile.length();

......

}

SDK 1.4 has handy classes for regular expression matching.
which may help to filter out fiels off the list.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top