* Created by IntelliJ IDEA.
* User: stefan
* Date: 2002-june-05
* Time: 05:10:16
* To change template for new class use
* Code Style | Class Templates options (Tools | IDE Options).
*/
import java.io.File;
import java.io.FileFilter;
* Constructor
*
* @param folderPath Root-folder where to start the search
* @param fileMask Part that must be in file that you are looking for
* (in your case ".ini")
*/
public ListFiles(String folderPath, String fileMask) {
findFiles(new File(folderPath), fileMask);
}
/**
* Find (recursively) all files with a specific
* mask and do something with each file...
*
* @param folder Root-folder where to start the search
* @param fileMask Part that must be in file that you are looking for
* (in your case ".ini")
*/
private void findFiles(File folder, final String fileMask) {
// since you are running Windows you probably don't care about case sensitivity...
final boolean ignoreCase = true;
File[] files = folder.listFiles(new FileFilter() {
public boolean accept(File file) {
String fileName = file.getName();
int index = fileName.length() - fileMask.length();
}
});
// content of the file and construct your xml-tags...); just printing them out here...
for (int i = 0; files != null && i < files.length; i++) {
if (files[i] != null) {
//...
System.out.println(files[i]);
//...
}
}
File[] folders = folder.listFiles(new FileFilter() {
public boolean accept(File dir) {
return dir.isDirectory();
}
});
// move to next folder (recursively) and do the
// above processing on the files found there
findFiles(folders[currentFolderIndex++], fileMask);
}
}
String folderPath = "c:\\temp";
String mask = ".txt";
}
}
To change your membership options, refer to:-----Ursprungligt meddelande-----
Fr�n: Mark Meyer [mailto:[EMAIL PROTECTED]]
Skickat: den 4 juni 2002 23:31
Till: JDJList
�mne: [jdjlist] finding files in a directory with a specific file mask
hi everyone..
i am making the conversion from delphi to java.
i am writing my first java utility app that will
1) loop through a given directory (on a windows box) looking for files with a specific file mask
2) then open up the file and interrogate the information inside (the files are actually .ini files)
3) and then write out the information in an XML format
my first task at hand is item 1)
i have classes/components written in Delphi to do recursive file searching - but i don't have a clue as to how to do this in java. any help, sources of information or guidance would be hugely appreciated.
any help or suggestions on items 2) and or 3) would also be appreciated.
thx
To change your membership options, refer to:
mark
http://www.sys-con.com/java/list.cfm
http://www.sys-con.com/java/list.cfm
