R
Rishi Dhupar
Hi,
I have written this recursion File scan, that is working perfectly in
Windows but of course just won't work in Unix.
Pretty simple, just goes thru directories and subdirectories and adds
any File it finds to a vector of type FileInfo. Any idea on how to get
to this to work on a Unix box?
Also should I be running the scan on the mounted name or the file
system name? Both do not seem to be working. Not too familiar with how
Unix filesystems work. For instance I run it on "FileScan.jar /boot"
Program says it isn't a valid directory, but f I run "FileScan.jar /"
Doesn't give error of not a directory, Java gives this error.
Exception in thread "main" java.lang.NullPointerException
at java.io.File.File(java.lang.String, java.lang.String)
(/usr/lib/libgcj.so.
5.0.0)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build() (Unknown Source)
at Main.main(java.lang.String[]) (Unknown Source)
private FileInfo build(File f) {
if (f.getPath().indexOf("System Volume Information")!= -1) return
null;
if (!f.exists()) return null;
if (!f.isDirectory()) return null;
// f is an existing directory
String path = f.getPath();
String name = f.getName();
//FileInfo mdir = new FileInfo(path, name);
// Loop thru files and directories in this path
String[] files = f.list();
for (int i = 0; i < files.length; i++) {
File f2 = new File(path, files);
if (f2.isFile()) {
//mdir.addFile(new FileInfo(path, files,f2.length()));
this.addFile(new FileInfo((path + "\\"), files,f2.length()));
} else if (f2.isDirectory()) {
File f3 = new File(path, files);
FileInfo m = build(f3); // recursive call
//if (m != null) { mdir.addDir(m); }
}
}
return mdir;
}
Thanks you very much
I have written this recursion File scan, that is working perfectly in
Windows but of course just won't work in Unix.
Pretty simple, just goes thru directories and subdirectories and adds
any File it finds to a vector of type FileInfo. Any idea on how to get
to this to work on a Unix box?
Also should I be running the scan on the mounted name or the file
system name? Both do not seem to be working. Not too familiar with how
Unix filesystems work. For instance I run it on "FileScan.jar /boot"
Program says it isn't a valid directory, but f I run "FileScan.jar /"
Doesn't give error of not a directory, Java gives this error.
Exception in thread "main" java.lang.NullPointerException
at java.io.File.File(java.lang.String, java.lang.String)
(/usr/lib/libgcj.so.
5.0.0)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build(java.io.File) (Unknown Source)
at MyFileStructure.build() (Unknown Source)
at Main.main(java.lang.String[]) (Unknown Source)
private FileInfo build(File f) {
if (f.getPath().indexOf("System Volume Information")!= -1) return
null;
if (!f.exists()) return null;
if (!f.isDirectory()) return null;
// f is an existing directory
String path = f.getPath();
String name = f.getName();
//FileInfo mdir = new FileInfo(path, name);
// Loop thru files and directories in this path
String[] files = f.list();
for (int i = 0; i < files.length; i++) {
File f2 = new File(path, files);
if (f2.isFile()) {
//mdir.addFile(new FileInfo(path, files,f2.length()));
this.addFile(new FileInfo((path + "\\"), files,f2.length()));
} else if (f2.isDirectory()) {
File f3 = new File(path, files);
FileInfo m = build(f3); // recursive call
//if (m != null) { mdir.addDir(m); }
}
}
return mdir;
}
Thanks you very much