Skip to content

Instantly share code, notes, and snippets.

@Viacheslav77
Created February 1, 2016 10:48
Show Gist options
  • Select an option

  • Save Viacheslav77/97da60125dadc7d55b65 to your computer and use it in GitHub Desktop.

Select an option

Save Viacheslav77/97da60125dadc7d55b65 to your computer and use it in GitHub Desktop.
Упрощённый вариан решения задачи :)
package Recursion;
/*Написать рекурсивную ф-ю для вывода на экран всех файлов и каталогов, имя которых длиннее 5
символов и вторая буква равна ‘A’. Упрощённый вариант*/
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
public class Main2 {
private static void listAll(String path, ArrayList<String> res)
throws IOException
{
File dir = new File(path);
for (File f : dir.listFiles()) {
if (f.isFile()) {
if ( f.getName().length()>1 && f.getName().length()<=8 && f.getName().charAt(1) == (char) 65)
System.out.println(" File : " + f.getCanonicalPath());
} else {
if ( f.getName().length()>1 && f.getName().length()<=8 && f.getName().charAt(1) == (char) 65)
System.out.println("Dir : " + f.getCanonicalPath());
listAll(f.getCanonicalPath(), res);
}
}
}
public static void main(String[] args) {
final String path = "d:\\1";
ArrayList<String> res = new ArrayList<String>();
try {
listAll(path, res);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment