xbn.util
Class DirFile

java.lang.Object
  |
  +--xbn.XBNObject
        |
        +--xbn.util.DirFile

public class DirFile
extends XBNObject

[Deprecated for DirScan] Represents a directory, and all files/directories/sub-directories/... therein. Every sub-directory in this one is another DirFile object.

Source code:  DirFile.java

This class is meant to be useful, not fast.

Example use

import xbn.util.DirFile;

public class XmplDirFile  {
   public static void main(String[] as_cmdLineParams)  {
      DirFile df = new DirFile(".");      //The directory you're executing this from

      System.out.println(df.toString());
      listFiles(df, "   ");
   }

   public static void listFiles(DirFile df, String s_dbgPrefix)  {
      for(int i = 0; i < df.getCountSubFiles(); i++)  {
         System.out.println(s_dbgPrefix + df.getSubFile(i).getFileObjectThis().getName());
      }

      for(int i = 0; i < df.getCountSubDirs(); i++)  {
         System.out.println(s_dbgPrefix + "[" + df.getSubDir(i).getFileObjectThis().getName() + "]");
         listFiles(df.getSubDir(i), (s_dbgPrefix + "   "));
      }
   }
}


Fields inherited from class xbn.XBNObject
bFALSE_IN_PRODUCTION, bTRUE_IN_PRODUCTION, sCNSTR, sES, sLINE_SEP
 
Constructor Summary
DirFile(String s_basePath)
          Create a DirFile.
DirFile(String s_basePath, FileFilter file_filter)
          Create a DirFile.
DirFile(String s_basePath, FileFilter file_filter, Outputter o_utputter)
          Create a DirFile.
DirFile(String s_basePath, int i_levelsToAnalyze)
          Create a DirFile.
DirFile(String s_basePath, int i_levelsToAnalyze, FileFilter file_filter)
          Create a DirFile.
DirFile(String s_basePath, int i_levelsToAnalyze, FileFilter file_filter, Outputter o_utputter)
          Create a DirFile.
DirFile(String s_basePath, int i_levelsToAnalyze, Outputter o_utputter)
          Create a DirFile.
DirFile(String s_basePath, Outputter o_utputter)
          Create a DirFile.
 
Method Summary
 int getCountSubDirs()
          How many sub-directories exist in this directory?
 int getCountSubFiles()
          How many sub-files exist in this directory?
 File getFileObjBaseDir()
          Get the java.io.File representing the base directory.
 File getFileObjectBaseDir()
          Deprecated. Use getFileObjBaseDir.
 File getFileObjectThis()
          Deprecated. Use getFileObjThis.
 File getFileObjThis()
          Get the java.io.File representing this file/directory.
 int getLevelsBelowBaseDir()
          How many levels below the base directory is this file/dir?
 int getLevelsToAnalyze()
          How many levels of sub-directories (and their contents) should be analyzed?
 String getRelativeDirectory()
          Deprecated. Use getRelDir.
 String getRelDir()
          Get the relative path of this DirFile.
 DirFile getSubDir(int i_dx)
          Get the sub directory at the requested array index.
 DirFile getSubFile(int i_dx)
          Get the sub file at the requested array index.
 boolean haveContentsBeenAnalyzed()
          Does this DirFile represent a directory, and have its contents been analyzed?
 boolean isDirectory()
          Does this DirFile object represent a directory?
 boolean isFile()
          Does this DirFile object represent a file?
 String toString()
          Get some information about this DirFile.
 
Methods inherited from class xbn.XBNObject
getXMsgPrefix, sop, sopl, sopl, throwAX, throwAXIfBadStr, throwAXIfNull, throwAXSpoof
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DirFile

public DirFile(String s_basePath)

Create a DirFile.

Equal to DirFile(s_basePath, (new Outputter()))


DirFile

public DirFile(String s_basePath,
               Outputter o_utputter)

Create a DirFile.

Equal to DirFile(s_basePath, -1, o_utputter)


DirFile

public DirFile(String s_basePath,
               int i_levelsToAnalyze)

Create a DirFile.

Equal to DirFile(s_basePath, i_levelsToAnalyze, (new Outputter()))


DirFile

public DirFile(String s_basePath,
               int i_levelsToAnalyze,
               Outputter o_utputter)

Create a DirFile.

Equal to DirFile(s_basePath, i_levelsToAnalyze, null, o_utputter)


DirFile

public DirFile(String s_basePath,
               FileFilter file_filter)

Create a DirFile.

Equal to DirFile(s_basePath, -1, file_filter)

Note: To pass in file_filter as null, use

(new DirFile("Base path", (FileFilter)file_filter))


DirFile

public DirFile(String s_basePath,
               int i_levelsToAnalyze,
               FileFilter file_filter)

Create a DirFile.

Equal to DirFile(s_basePath, i_levelsToAnalyze, file_filter, (new Outputter())))


DirFile

public DirFile(String s_basePath,
               FileFilter file_filter,
               Outputter o_utputter)

Create a DirFile.

Equal to DirFile(s_basePath, -1, null)


DirFile

public DirFile(String s_basePath,
               int i_levelsToAnalyze,
               FileFilter file_filter,
               Outputter o_utputter)

Create a DirFile.

Parameters:
s_basePath - The full path (including the final File.separator) of the base directory. May not be null, and must represent a directory that exists.
i_levelsToAnalyze - The number of levels to analyze. must be greater than -2. See getLevelsToAnalyze.
file_filter - The java.io.FileFilter object to define the specific files and directories that should be retrieved. If all files are desired, set this to null.
Method Detail

getFileObjectThis

public File getFileObjectThis()
Deprecated. Use getFileObjThis.

Get the java.io.File representing this file/directory.

Returns:
getFileObjThis()

getFileObjectBaseDir

public File getFileObjectBaseDir()
Deprecated. Use getFileObjBaseDir.

Get the java.io.File representing the base directory.

Returns:
getFileObjBaseDir()

getRelativeDirectory

public String getRelativeDirectory()
Deprecated. Use getRelDir.

Get the relative path of this DirFile.

Returns:
getRelDir()

getFileObjBaseDir

public File getFileObjBaseDir()

Get the java.io.File representing the base directory.

If getFileObjThis equals getFileObjBaseDir, then this DirFile is the base directory.


getFileObjThis

public File getFileObjThis()

Get the java.io.File representing this file/directory.

If getFileObjBaseDir equals getFileObjThis, then this DirFile is the base directory.


getRelDir

public String getRelDir()

Get the relative path of this DirFile.

May be giving an extra parent directory. May be actually returning dir\sub_dir\another_sub_dir

Returns:
"" If this is the base directory.
If this is not the base directory:  The full path of this DirFile, minus the path of the base directory and minus the name itself. It neither starts nor ends with a slash.

For example, if...

  • Base directory: C:\dir
  • This DirFile: C:\dir\sub_dir\another_sub_dir\file.txt

Then this function would return "sub_dir\another_sub_dir"


getCountSubDirs

public int getCountSubDirs()

How many sub-directories exist in this directory?

Returns:
0
  • If this DirFile is a file.
  • If this DirFile is a directory, but there are no directories contained in it.
  • If this DirFile is a directory, but the contents have not been analyzed (haveContentsBeenAnalyzed equals false).
A number greater than 0 If this DirFile is a directory, and there is at least one directory contained in it.

getCountSubFiles

public int getCountSubFiles()

How many sub-files exist in this directory?

Returns:
0
  • If this DirFile is a file.
  • If this DirFile is a directory, but there are no files contained in it.
  • If this DirFile is a directory, but the contents have not been analyzed (haveContentsBeenAnalyzed equals false).

A number greater than 0 If this DirFile is a directory, and there is at least one file contained in it.

getSubFile

public DirFile getSubFile(int i_dx)

Get the sub file at the requested array index.

Parameters:
i_dx - The array index of the sub file you wish to retrieve. Must range zero..[getCountSubFiles - 1], inclusive.
Returns:
A DirFile representing the sub-file (as contained in this directory) at array index i_dx.
Throws:
AssertException
    -
  • If there are no sub-files.
  • If this DirFile object is a file (and therefore contains no sub-files).
  • If this DirFile object is a directory, but there are no sub-files contained in it (getCountSubFiles equals 0).
  • If this DirFile is a directory, may or may not have sub-files, but its contents have not been analyzed (haveContentsBeenAnalyzed equals false).

getSubDir

public DirFile getSubDir(int i_dx)

Get the sub directory at the requested array index.

Parameters:
i_dx - The array index of the sub directory you wish to retrieve. Must range zero..[getCountSubDirs - 1], inclusive.
Returns:
A DirFile representing the sub-directory (as contained in this directory) at array index i_dx.
Throws:
AssertException
    -
  • If there are no sub-directories.
  • If this DirFile object is a file (and therefore contains no sub-directories).
  • If this DirFile object is a directory, but there are no sub-directories contained in it (getCountSubFiles equals 0).
  • If this DirFile is a directory, may or may not have sub-directories, but its contents have not been analyzed (haveContentsBeenAnalyzed equals false).

isDirectory

public boolean isDirectory()

Does this DirFile object represent a directory?

Returns:
true If this DirFile represents a directory.
false If this DirFile represents a file.

isFile

public boolean isFile()

Does this DirFile object represent a file?

Returns:
true If this DirFile represents a file.
false If this DirFile represents a directory.

haveContentsBeenAnalyzed

public boolean haveContentsBeenAnalyzed()

Does this DirFile represent a directory, and have its contents been analyzed?

Depending on the value of getLevelsToAnalyze, this directory (if it is a directory) may not be analyzed or recognized by this DirFile. In other words, this directory may be at the bottom level, in which case its contents are ignored. This is not a statement to whether the directory contains zero or [not-zero] objects in it.

Returns:
true If this DirFile is a directory, and the contents (the files and directories) of it have been analyzed.
false If this DirFile is a file, or if it's a directory but the contents of it have not been analyzed.

getLevelsBelowBaseDir

public int getLevelsBelowBaseDir()

How many levels below the base directory is this file/dir?

Returns:
0 If this file/dir is directory in the base directory, or is the base directory.
1 If this file/dir is in a directory directly contained in the base directory.
2... If this file/dir is in a directory 2 (or more) levels below the base directory.

getLevelsToAnalyze

public int getLevelsToAnalyze()

How many levels of sub-directories (and their contents) should be analyzed?

Returns:
-1 Analyze everything. The contents of this directory, contents of any directories in this one, all their contents, all their sub-directories, ...
0 Analyze nothing further, even if this DirFile is a directory. This analyzes the current directory (file) itself, but nothing inside of it.
1 Analyze the contents of this directory, but not the contents of anything else, even if this directory contains another directory.
2 Same as 1, but analyze the contents of sub-directories (directories that are in this one). Do not analyze the contents of any sub-sub-directories.
3 Same as 2, but analyze the contents of the sub-sub-directories as well.
4 Same as 3, but analyze the contents of the sub-sub-sub-directories as well.
... Same as 4, but analyze the contents of the sub-sub-sub-...-directories as well.

toString

public String toString()

Get some information about this DirFile.

Overrides:
toString in class Object



Copyright 1997-2003, Jeff Epstein, All Rights Reserved. See top of source code files for copyright notice.

 

http://sourceforge.net/projects/xbnjava

 

SourceForge.net Logo