Re: File Scanning on a Unix Box



Rishi Dhupar wrote:

> 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[i]);
> if (f2.isFile()) {
> //mdir.addFile(new FileInfo(path, files[i],f2.length()));
> this.addFile(new FileInfo((path + "\\"), files[i],f2.length()));
> } else if (f2.isDirectory()) {
> File f3 = new File(path, files[i]);
> FileInfo m = build(f3); // recursive call
> //if (m != null) { mdir.addDir(m); }
> }
> }
> return mdir;
> }
>
>
>
> Thanks you very much

UNIX has a thing called "security", something which Windows hasn't really
got to grips with yet.

If you don't have read permission on a directory you can't read the
contents, and the line String[] files = f.list(); will return null. You
blithely go on to use files.length on the next line without bothering to
test whether files is null.



--
Nigel Wade, System Administrator, Space Plasma Physics Group,
University of Leicester, Leicester, LE1 7RH, UK
E-mail : nmw@xxxxxxxxxxxx
Phone : +44 (0)116 2523548, Fax : +44 (0)116 2523555
.



Relevant Pages

  • Exchange 5.5 OWA - using Windows XP client java error
    ... Users that connect to OWA which are running Windows XP ... This is what I captured from the Java console by right ... v: dump thread stack ... (Unknown Source) ...
    (microsoft.public.exchange.clients)
  • File Scanning on a Unix Box
    ... I have written this recursion File scan, ... Windows but of course just won't work in Unix. ... at MyFileStructure.build(Unknown Source) ...
    (comp.lang.java.programmer)
  • Re: File Scanning on a Unix Box
    ... > I have written this recursion File scan, ... > Windows but of course just won't work in Unix. ... > at MyFileStructure.build(Unknown Source) ...
    (comp.lang.java.programmer)
  • Re: File Scanning on a Unix Box
    ... > I have written this recursion File scan, ... > Windows but of course just won't work in Unix. ... > at MyFileStructure.build(Unknown Source) ...
    (comp.lang.java.programmer)
  • Re: Cannot delete directory
    ... Open a "DOS" window and navigate to the parent of the bad folder. ... Microsoft Windows MVP ... > some unknown source. ... > other directory is called temp and was created as a sub- ...
    (microsoft.public.win2000.file_system)