:shock:moerkstar hat gesagt.:und da bleibt er stehen
Leroy42 hat gesagt.:Gibts da überhaupt eine Datei die den String "txt" im
Dateinamen beinhaltet? :shock:
Was meinst du mit
moerkstar hat folgendes geschrieben:
und da bleibt er stehen
Looking in path: C:\usr\
Found 2 files.
C:\usr\FileFinder.class
C:\usr\FileFinder.java
import java.io.*;
import java.util.*;
public class FileFinder
{
public static void main( String[] args )
{
String filter[] = args;
File path = new File( System.getProperty("user.dir") );
System.out.println( "Looking in path: " + path );
FileFinder ff = new FileFinder();
List<File> files = ff.findFiles(path, filter, new ArrayList<File>());
System.out.printf( "Found %d file%s.%n",
files.size(), files.size() == 1 ? "" : "s" );
for (int i=0; i < files.size(); i++ ) {
File f = files.get(i);
System.out.println( f.getAbsolutePath() );
}
}
public List<File> findFiles(File root, String[] filters, List<File> found) {
File[] allSubFiles = root.listFiles();
for (int i=0; i < allSubFiles.length; i++) {
File f = allSubFiles[i];
if (f.isDirectory())
findFiles(f, filters, found);
else {
boolean accepted = true;
for (i=0; i<filters.length; i++) {
String s = filters[i];
if (!f.getName().toLowerCase().contains(s)) {
accepted = false;
break;
}}
if (accepted)
found.add(f);
}}
return found;
}
}
import java.io.*;
import java.util.*;
public class FileFinder
{
public static void main( String[] args )
{
String filter[] = args;
File path = new File( System.getProperty("user.dir") );
System.out.println( "Looking in path: " + path );
FileFinder ff = new FileFinder();
List<File> files = ff.findFiles(path, filter);
System.out.printf( "Found %d file%s.%n",
files.size(), files.size() == 1 ? "" : "s" );
for ( File f : files )
System.out.println( f.getAbsolutePath() );
}
public List<File> findFiles(File rootDir, String[] filters) {
return findFiles(rootDir, filters, new ArrayList<File>());
}
public List<File> findFiles(File root, String[] filters, List<File> found) {
for (File f : root.listFiles())
if (f.isDirectory())
findFiles(f, filters, found);
else {
boolean accepted = true;
for (String s : filters)
if (!f.getName().contains(s)) {
accepted = false;
break;
}
if (accepted)
found.add(f);
}
return found;
}
}
for (int j=0;j <filters.length; j++) {
String s = filters[j];
if (!f.getName().toLowerCase().contains(s)) {
accepted = false;
break;
}}
import java.io.*;
import java.util.*;
public class FileFinder {
public static void main( String[] args ) {
String filter[] = args;
File path = new File( System.getProperty("user.dir") );
System.out.println( "Looking in path: " + path );
FileFinder ff = new FileFinder();
List<File> files = ff.findFiles(path, filter, new ArrayList<File>());
System.out.printf( "Found %d file%s.%n", files.size(), files.size() == 1 ? "" : "s" );
for (int i=0; i < files.size(); i++ ) {
File f = files.get(i);
System.out.println( f.getAbsolutePath() );
}
}
public List<File> findFiles(File root, String[] filters, List<File> found) {
File[] allSubFiles = root.listFiles();
for (int i=0; i < allSubFiles.length; i++) {
File f = allSubFiles[i];
if (f.isDirectory())
findFiles(f, filters, found);
else {
boolean accepted = true;
for (int j=0; j<filters.length; j++) {
String s = filters[j];
if (!f.getName().toLowerCase().contains(s)) {
accepted = false;
break;
}
}
if (accepted)
found.add(f);
}
}
return found;
}
}
import java.io.*;
import java.util.*;
public class FileFinder {
public static void main( String[] args ) {
String filter[] = args;
boolean onlyDir = false;
for (int k=0; k<filter.length; k++) {
String dir = filter[k];
if (dir.equalsIgnoreCase("-d")) {
onlyDir = true;
filter[k] = "";
break;
}
}
File path = new File( System.getProperty("user.dir") );
System.out.println( "Looking in path: " + path );
FileFinder ff = new FileFinder();
List<File> files = ff.findFiles(path, filter, new ArrayList<File>(), onlyDir);
System.out.printf( "Found %d file%s.%n", files.size(), files.size() == 1 ? "" : "s" );
for (int i=0; i < files.size(); i++ ) {
File f = files.get(i);
System.out.println( f.getAbsolutePath() );
}
}
public List<File> findFiles(File root, String[] filters, List<File> found, boolean onlyDir) {
File[] allSubFiles = root.listFiles();
if (onlyDir) {
for (int i=0; i < allSubFiles.length; i++) {
File f = allSubFiles[i];
if (f.isDirectory()) {
boolean accepted = true;
for (int j=0; j<filters.length; j++) {
String s = filters[j];
if (!f.getName().toLowerCase().contains(s)) {
accepted = false;
break;
}
}
if (accepted)
found.add(f);
findFiles(f, filters, found, onlyDir);
}
}
}
else {
for (int i=0; i < allSubFiles.length; i++) {
File f = allSubFiles[i];
if (f.isDirectory())
findFiles(f, filters, found, onlyDir);
else {
boolean accepted = true;
for (int j=0; j<filters.length; j++) {
String s = filters[j];
if (!f.getName().toLowerCase().contains(s)) {
accepted = false;
break;
}
}
if (accepted)
found.add(f);
}
}
}
return found;
}
}