• Main Page
  • Classes
  • Files
  • File List
  • File Members

Beesnest/Windows/DcFileUtil.h

Go to the documentation of this file.
00001 /*
00002 Copyright 2007 Erez Bibi (erezbibi@users.sourceforge.net)
00003 This file is part of Beesnest.
00004 
00005 Beesnest is free software; you can redistribute it and/or modify
00006 it under the terms of the GNU General Public License as published by
00007 the Free Software Foundation; either version 2 of the License, or
00008 (at your option) any later version.
00009 
00010 Beesnest is distributed in the hope that it will be useful,
00011 but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 GNU General Public License for more details.
00014 
00015 You should have received a copy of the GNU General Public License
00016 along with Beesnest; if not, write to the Free Software
00017 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 */
00019 
00020 /* DcFileUtil.h: interface for the CdcFileUtil class. */
00021 
00022 #ifndef __CDC_FILE_UTIL
00023 #define __CDC_FILE_UTIL
00024 
00025 #include "../DcGlobals.h"
00026 #include "../DcString.h"
00027 #include "../DcExceptionFile.h"
00028 #include "../DcHttpTime.h"
00029 
00030 /** Vector to hold files names. */
00031 typedef vector <CdcString> t_files_vector;
00032 
00033 /**
00034  * This class defines some file utilities. I need it to be OS Independent.
00035  * Getting information about the file is a non-static operation. The first
00036  * query about file info will get the file info from the file system. Then
00037  * any query will just returns info from the same structure.
00038  *
00039  * In addition I have here:
00040  * Get a list of files in a directory - static.
00041  * Get the run-time path - static.
00042  *
00043  * <p>
00044  * @author Erez Bibi
00045  * @version 1.0
00046  */
00047 class CdcFileUtil
00048 {
00049 private:
00050 
00051     /** Windows file status struct. */
00052     struct stat oFileStatus;
00053 
00054     /** Indicate that the constructor has found the file. */
00055     bool isFileFound;
00056 
00057     /** The program run-time path - static. */
00058     static CdcString sWorkPath;
00059 
00060 public:
00061     /**
00062      * Constructor - empty.
00063      */
00064      CdcFileUtil () :isFileFound(false) {}
00065 
00066     /**
00067      * Destructor - empty
00068      */
00069     virtual ~CdcFileUtil () {}
00070 
00071     /**
00072      * Load File info from file system.
00073      * <p>
00074      * @param file_name The file name and path.
00075      */
00076     bool OpenFile (const CdcString& file_name);
00077 
00078 
00079     /**
00080      * Returns the file last-modified time.
00081      * <p>
00082      * @param gmt True if need time in GMT form.
00083      */
00084     CdcHttpTime GetFileLastModified (bool gmt);
00085 
00086     /**
00087      * Returns the file size in bytes.
00088      */
00089     int GetFileSize ();
00090 
00091     /**
00092      * Static function to return the path where the application is running.
00093      * This function will check for the program path just once!
00094      */
00095     static CdcString GetProgramPath ();
00096 
00097     /**
00098      * Returns the working path of this program. If the path supplied
00099      * as parameter is not an absolute path, it returns the base path
00100      * + the parameter path. Otherwise it just returns the path without
00101      * changing it.
00102      * <p>
00103      * @param path The path to add the work path to.
00104      * @return (CdcString) The compleate absolute path.
00105      */
00106     static CdcString GetWorkPath (const CdcString& path);
00107 
00108     /**
00109      * This static function return a vector with all files (with specific
00110      * extension) in a directory.
00111      * <p>
00112      * @param dir_path The path to the directory to scan.
00113      * @param file_ext The extension of the files to get. '*' will return all
00114      *  files.
00115      */
00116     static t_files_vector GetAllFilesInDir (const CdcString& dir_path,
00117                                             const CdcString& file_ext);
00118 };
00119 
00120 
00121 #endif  /* __CDC_FILE_UTIL */
00122 

Generated on Mon Oct 11 2010 16:23:25 for Beesnest by  doxygen 1.7.2