filesystem
Class FileExtended

java.lang.Object
  extended by java.io.File
      extended by filesystem.FileExtended
All Implemented Interfaces:
java.io.Serializable, java.lang.Comparable<java.io.File>

public class FileExtended
extends java.io.File

Extends File to provide features missing from the Sun File class. Also, features a copy and delete (for file and dir) operation.

Author:
Tandeep
See Also:
Serialized Form

Field Summary
 
Fields inherited from class java.io.File
pathSeparator, pathSeparatorChar, separator, separatorChar
 
Constructor Summary
FileExtended(FileExtended parent, java.lang.String file)
          Calls the File constructor
FileExtended(java.io.File parent, java.lang.String fileName)
          Constructor.
FileExtended(java.lang.String pathname)
          Calls the File constructor
FileExtended(java.lang.String parent, java.lang.String fileName)
          Constructor.
 
Method Summary
static void copy(java.io.File destDir, java.io.File srcFile)
          Copies a file or directory to dest dir.
 boolean delete()
          Deletes this file/directory.
 java.lang.String getHomeDir()
          Returns the drive name where this file is.
 java.lang.String getNameWithoutExtension()
          Returns the name of the file as defined by File.getName() without any attached extension.
 int getPageNumber()
          Given any filename, returns any series of digits in that filename.
static int getPageNumber(java.lang.String s)
           
 java.lang.String getPageNumberPrefix()
          Returns page number prefix.
static java.util.ArrayList<java.io.File> listAllFiles(java.io.File dicFile)
          Returns all files in a directory.
 java.io.File[] listFiles()
          Overrides listFiles in File#listFiles() to only accept files that are not named "CVS".
 java.io.File[] listFiles(java.lang.String extension)
          Finds all files in a dir.
static java.io.File removeExtension(java.io.File element)
          Given any filename, returns the same file but without the extension(if any)
 
Methods inherited from class java.io.File
canRead, canWrite, compareTo, createNewFile, createTempFile, createTempFile, deleteOnExit, equals, exists, getAbsoluteFile, getAbsolutePath, getCanonicalFile, getCanonicalPath, getName, getParent, getParentFile, getPath, hashCode, isAbsolute, isDirectory, isFile, isHidden, lastModified, length, list, list, listFiles, listFiles, listRoots, mkdir, mkdirs, renameTo, setLastModified, setReadOnly, toString, toURI, toURL
 
Methods inherited from class java.lang.Object
getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

FileExtended

public FileExtended(java.lang.String pathname)
Calls the File constructor

Parameters:
pathname -

FileExtended

public FileExtended(java.io.File parent,
                    java.lang.String fileName)
Constructor.

Parameters:
parent - parent directory
fileName - the name of the file

FileExtended

public FileExtended(java.lang.String parent,
                    java.lang.String fileName)
Constructor.

Parameters:
parent - parent directory
fileName - the name of the file

FileExtended

public FileExtended(FileExtended parent,
                    java.lang.String file)
Calls the File constructor

Method Detail

listFiles

public java.io.File[] listFiles(java.lang.String extension)
Finds all files in a dir. with a particular extension

See Also:
File class File#listFiles(FileFilter) for more details

getNameWithoutExtension

public java.lang.String getNameWithoutExtension()
Returns the name of the file as defined by File.getName() without any attached extension. For filename "image.jpg" will return "image" Assumption: Extension starts by the last dot(.) in the file name


listFiles

public java.io.File[] listFiles()
Overrides listFiles in File#listFiles() to only accept files that are not named "CVS". This excludes the cvs files/directories. Useful because our current system has these CVS dirs. which disrupt the system (non-Javadoc)

Overrides:
listFiles in class java.io.File
See Also:
File.listFiles()

delete

public boolean delete()
Deletes this file/directory. Can delete files and directory even non-empty.

Overrides:
delete in class java.io.File
Returns:
True if the file/directory successfuly deleted; false, otherwise
See Also:
for more details about deleting a file

copy

public static void copy(java.io.File destDir,
                        java.io.File srcFile)
                 throws java.io.FileNotFoundException,
                        java.io.IOException
Copies a file or directory to dest dir. The file can be dir or a file.

Parameters:
destDir - Complete path to the destination directory
srcFile - Complete path to the source file/directory
Throws:
java.io.FileNotFoundException - Throws FileNotFoundException if srcFile not found
java.io.IOException - Throws IOException if destDir not absolute or does not exist

removeExtension

public static java.io.File removeExtension(java.io.File element)
Given any filename, returns the same file but without the extension(if any)

Parameters:
element -
Returns:

getPageNumber

public static int getPageNumber(java.lang.String s)

getPageNumber

public int getPageNumber()
Given any filename, returns any series of digits in that filename.
 Example: for ce001,  returns 1
 for ce0001-002, returns 1
 for ce21dd, returns 21
 for 21dd, returns 21
 for cebdef return -1
 


getPageNumberPrefix

public java.lang.String getPageNumberPrefix()
Returns page number prefix. for a filename ce0001, will return ce


getHomeDir

public java.lang.String getHomeDir()
Returns the drive name where this file is. Returns null, if the path for this file is not absolute(in which case there is no drive name) Example: For filename: C:\Hello\World.txt, returns "C"
Not sure if this will work on any other system besides Windows


listAllFiles

public static java.util.ArrayList<java.io.File> listAllFiles(java.io.File dicFile)
Returns all files in a directory. If the directory contains some sub-directories, then those files within those folders are also returned including the subfolders.

If a file is passed to this function instead of a directory, only that file is returned.

Parameters:
fileName - Name of the directory
Returns:
ArrayList of Files