Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include "DcFileUtil.h"
00026
00027 CdcString CdcFileUtil::sWorkPath;
00028
00029 bool CdcFileUtil::OpenFile (const CdcString& file_name)
00030 {
00031 isFileFound = (stat (file_name.GetBuffer (), &oFileStatus) == 0);
00032 return isFileFound;
00033 }
00034
00035
00036 CdcHttpTime CdcFileUtil::GetFileLastModified (bool gmt)
00037 {
00038 if (isFileFound == false)
00039 throw (CdcExceptionFile ("File not found",
00040 DC_FILE_NOT_FOUND_EXP));
00041
00042 return CdcHttpTime ((time_t)oFileStatus.st_mtime, gmt);
00043 }
00044
00045 int CdcFileUtil::GetFileSize ()
00046 {
00047 if (isFileFound == false)
00048 throw (CdcExceptionFile ("File not found",
00049 DC_FILE_NOT_FOUND_EXP));
00050
00051 return oFileStatus.st_size;
00052 }
00053
00054
00055 CdcString CdcFileUtil::GetProgramPath ()
00056 {
00057 if (sWorkPath.IsEmpty ())
00058 {
00059 char temp [BUFF_LEN];
00060 GetModuleFileName (0, temp, BUFF_LEN);
00061 *(strrchr (temp, '\\') + 1) = '\0';
00062 sWorkPath = temp;
00063 }
00064 return sWorkPath;
00065 }
00066
00067 CdcString CdcFileUtil::GetWorkPath (const CdcString& path)
00068 {
00069 if (strlen (path) > 1 && path[1] == ':')
00070 return path;
00071 return GetProgramPath() + path;
00072 }
00073
00074
00075
00076 t_files_vector CdcFileUtil::GetAllFilesInDir (const CdcString& dir_path,
00077 const CdcString& file_ext)
00078 {
00079 WIN32_FIND_DATA file_data;
00080 t_files_vector file_vct;
00081 CdcString files = dir_path + "*." + file_ext;
00082 int ret;
00083
00084
00085 HANDLE hnd = FindFirstFile (files.GetBuffer (), &file_data);
00086 if (hnd == INVALID_HANDLE_VALUE)
00087 throw (CdcExceptionFile ("Cannot open files", DC_FILE_EXP));
00088
00089 do
00090 {
00091 file_vct.push_back (dir_path + file_data.cFileName);
00092
00093 ret = FindNextFile (hnd, &file_data);
00094 }
00095 while (ret != 0);
00096
00097 FindClose (hnd);
00098 return file_vct;
00099 }
00100