Get file name from folder

Hi all,

how to find a .txt file in a particular folder. My text file comes with

following name <fixed_name>.<mmddyy><hhmmss>, e.g., fn_fnprod.102806015605

so how to get this file name. nd also tell me if there are multiple files

then how to retrieve the oldest one first and so on....

Thanks & Regards

Gaurav

[373 byte] By [HCLitsa] at [2007-10-3 10:23:28]
# 1

look at the File API.

File f = new File("folderpath");

File[] fList = f.listFiles();

//loop here

for(int i = 0; i < fList.length ; i+;){

f[i].getName();

}

lupansanseia at 2007-7-15 5:45:13 > top of Java-index,Java Essentials,Java Programming...
# 2
it's fine but how to know which is older file b'cpz this file comes every day with new date & time. so what if there a multiple file. nd i have proceed oldest first.pls help asap
HCLitsa at 2007-7-15 5:45:13 > top of Java-index,Java Essentials,Java Programming...
# 3

> it's fine but how to know which is older file b'cpz

> this file comes every day with new date & time. so

> what if there a multiple file. nd i have proceed

> oldest first.

> pls help asap

get each file last modifed, using file.lastModified() method and compare which file you would be needing. =)

Redxxiva at 2007-7-15 5:45:13 > top of Java-index,Java Essentials,Java Programming...
# 4
1. Loop file array2. For each matching file parse date and time information using SimpleDateFormat and save this along with the file name in a list3. Sort list ascending by date4. Proceed list
quittea at 2007-7-15 5:45:13 > top of Java-index,Java Essentials,Java Programming...