Hello
I need some help with a recursive function that is supposed to read dirs from an arbitrary location from the file system. When I call the function the second time from within the function no subdirs are found, I don’t think the file filter is called. Please help me out. My code looks like this:
Thank you!
public void buildStructure(File filename, FileObject parent)
{
this.parent = parent;
this.workDir = filename;
System.out.println("workDir is " + filename);
FileFilter fileFilter = new FileFilter()
{
public boolean accept(File file)
{
boolean b = file.isDirectory();
System.out.println("isdir " + b);
return b;
}
};
/*Check if there is any subdirs in dir <filename>*/
File[] subDirs = workDir.listFiles(fileFilter);
FileObject fob = new FileObjectImpl(workDir, parent);
if (subDirs == null)
{
System.out.println("Subdirs is null"
}
else
{
System.out.println("subDirs length " + subDirs.length);
for (int i = 0; i < subDirs.length; i++)
{
System.out.println("addsub dir " + subDirs);
fob.addSubDir(new FileObjectImpl(subDirs,fob));
buildStructure(subDirs,fob);
}
}
}
I need some help with a recursive function that is supposed to read dirs from an arbitrary location from the file system. When I call the function the second time from within the function no subdirs are found, I don’t think the file filter is called. Please help me out. My code looks like this:
Thank you!
public void buildStructure(File filename, FileObject parent)
{
this.parent = parent;
this.workDir = filename;
System.out.println("workDir is " + filename);
FileFilter fileFilter = new FileFilter()
{
public boolean accept(File file)
{
boolean b = file.isDirectory();
System.out.println("isdir " + b);
return b;
}
};
/*Check if there is any subdirs in dir <filename>*/
File[] subDirs = workDir.listFiles(fileFilter);
FileObject fob = new FileObjectImpl(workDir, parent);
if (subDirs == null)
{
System.out.println("Subdirs is null"
}
else
{
System.out.println("subDirs length " + subDirs.length);
for (int i = 0; i < subDirs.length; i++)
{
System.out.println("addsub dir " + subDirs);
fob.addSubDir(new FileObjectImpl(subDirs,fob));
buildStructure(subDirs,fob);
}
}
}