I am trying to do some file editing in a directory which has some subfolders in it. However my java app doesnt go in depths of subfolders and only do operation in first subfolders like below
Folder1 (works) -folder11 (works) --files(works) --folder111 (doesnt work) -folder12(works) --files(works) -folder13(works) --files(works)
What am i doing wrong?
Here is my code:
btnBasla.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
File dir= new File(Path2.toString());
File files[]=dir.listFiles();
for (File f: files) {
if (f.isDirectory()) {
try {
listDir(f.toString());
} catch (IOException e1) {
e1.printStackTrace();
}
} else {
if(f.getName().lastIndexOf('.')>0) {
int lastIndex = f.getName().lastIndexOf('.');
String str = f.getName().substring(lastIndex);
if(str.equals(".txt") || str.equals(".sub") || str.equals(".srt")) {
try {
String sonuc = islem.koddegıstır(f.getAbsolutePath());
textField.append(sonuc+"\n");
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}
}
}
public void listDir (String dir) throws IOException{
File place = new File(dir);
if(place.isDirectory()){
File files[]= place.listFiles();
for (File f:files) {
if (f.isDirectory()) {
listDir(f.getName());
} else {
if(f.getName().lastIndexOf('.')>0) {
int lastIndex = f.getName().lastIndexOf('.');
String str = f.getName().substring(lastIndex);
if(str.equals(".txt") || str.equals(".sub") || str.equals(".srt")) {
String sonuc = islem.koddegıstır(f.getAbsolutePath());
textField.append(sonuc+"\n");
}
}
}
}
}
}
});