What is the wildcard code..?
i am writing a program. I want the program to search for all files that end with one extension, and i want it to rename it to another extension...
example
test.java -> test.dat
(not to encode it.)
ok... i have the actual rename done, but how do i get it to do all files that end with the extension?
here is pretty much the bulk
File z = new File("dv.txt");
z.renameTo(new File("dv.dat"));
that little excerpt renames the file, but how do i get it to do all (filename).txt to (filename).dat with in a directory?
Thank you!
[587 byte] By [
pros599a] at [2007-11-26 12:22:00]

# 4
Create a File instance for the directory.
File directory = new File("C:\\MyDirectory\\");
Create a FilenameFilter that will only accept files with the extension you want.
FilenameFilter filter = new FilenameFilter() {
public boolean accept(File dir, String name) {
return name.matches("*.txt");
}
};
Use listFiles(FilenameFilter) to get an array of File objects that represent every file in the directory that has a name with that extension.
File[] filesToRename = directory.listFiles(filter);
Then iterate over the array changing each file.