TCFile.h

Go to the documentation of this file.
00001 //*******************************************************************************
00002 //
00003 // *******   ***   ***               *
00004 //    *     *     *                  *
00005 //    *    *      *                *****
00006 //    *    *       ***  *   *   **   *    **    ***
00007 //    *    *          *  * *   *     *   ****  * * *
00008 //    *     *         *   *      *   * * *     * * *
00009 //    *      ***   ***    *     **   **   **   *   *
00010 //                        *
00011 //*******************************************************************************
00012 // see http://sourceforge.net/projects/tcsystem/ for details.
00013 // Copyright (C) 2003 - 2008 Thomas Goessler. All Rights Reserved. 
00014 //*******************************************************************************
00015 //
00016 // TCSystem is the legal property of its developers.
00017 // Please refer to the COPYRIGHT file distributed with this source distribution.
00018 // 
00019 // This library is free software; you can redistribute it and/or             
00020 // modify it under the terms of the GNU Lesser General Public                
00021 // License as published by the Free Software Foundation; either              
00022 // version 2.1 of the License, or (at your option) any later version.        
00023 //                                                                           
00024 // This library is distributed in the hope that it will be useful,           
00025 // but WITHOUT ANY WARRANTY; without even the implied warranty of            
00026 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         
00027 // Lesser General Public License for more details.                           
00028 //                                                                           
00029 // You should have received a copy of the GNU Lesser General Public          
00030 // License along with this library; if not, write to the Free Software       
00031 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
00032 //*******************************************************************************
00033 //  $Id: TCFile.h 891 2008-10-15 20:28:18Z the_____tiger $
00034 //*******************************************************************************
00035 
00036 #ifndef _TC_FILE_H_
00037 #define _TC_FILE_H_
00038 
00039 #include "TCSharedPtr.h"
00040 
00041 #include <string>
00042 #include <vector>
00043 
00044 namespace TC
00045 {
00061    namespace File
00062    {
00063       enum FileAttributes
00064       {
00065          FILEATTR_OWNER_WRITE          = 0x00000001,
00066          FILEATTR_OWNER_READ           = 0x00000002,
00067          FILEATTR_OWNER_EXEC           = 0x00000004,
00068          FILEATTR_GROUP_WRITE          = 0x00000008,
00069          FILEATTR_GROUP_READ           = 0x00000010,
00070          FILEATTR_GROUP_EXEC           = 0x00000020,
00071          FILEATTR_EVERYONE_WRITE       = 0x00000040,
00072          FILEATTR_EVERYONE_READ        = 0x00000080,
00073          FILEATTR_EVERYONE_EXEC        = 0x00000100,
00074 
00075          FILEATTR_READONLY             = 0x00000200,
00076          FILEATTR_ARCHIVE              = 0x00000400,
00077          FILEATTR_SYSTEM               = 0x00000800,
00078          FILEATTR_HIDDEN               = 0x00001000,
00079 
00080          FILEATTR_WRITE                = 0x00002000,
00081          FILEATTR_EXECUTE              = 0x00004000
00082 
00083       };
00084 
00086       TCBASE_API bool Exists(const std::string &file);
00088       TCBASE_API bool IsFile(const std::string &file);
00090       TCBASE_API bool IsDirectory(const std::string &file);
00092       TCBASE_API bool IsReadable(const std::string &file);
00094       TCBASE_API bool IsWriteable(const std::string &file);
00096       TCBASE_API bool IsExecutable(const std::string &file);
00097 
00099       TCBASE_API bool SetFileAttr(const std::string &file, uint32 attr);
00101       TCBASE_API uint64 GetFileSize(const std::string &file);
00102 
00104       TCBASE_API sint64 GetModificationTime(const std::string &file);
00106       TCBASE_API sint64 GetLastAccessTime(const std::string &file);
00108       TCBASE_API sint64 GetCreationTime(const std::string &file);
00110       TCBASE_API sint64 GetTouchedTime(const std::string &file);
00111 
00113       TCBASE_API std::string GetFileUser(const std::string &file);
00115       TCBASE_API std::string GetFileGroup(const std::string &file);
00116 
00118       TCBASE_API bool ChangeDirectory(const std::string &directoryIn);
00120       TCBASE_API std::string GetDirectory();
00122       TCBASE_API std::vector<std::string> GetFileListOfDirectory(const std::string &searchDirectory,
00123                                                             const std::string &searchExtension="");
00124       struct FileInfo
00125       {
00126          std::string name;
00127          sint64 last_modified;
00128          bool is_directory;
00129       };
00130       TCBASE_API void GetFileInfosOfDirectory(std::vector < FileInfo >& file_infos,
00131          const std::string & searchDirectory, 
00132          const std::string& searchExtension="");
00133 
00135       TCBASE_API bool Create(const std::string &file, bool removeOld=true);
00137       TCBASE_API bool Remove(const std::string &file);
00138 
00139       class Progress
00140       {
00141       public:
00142          virtual void OnCurrentStatus(uint32 percent_done) = 0;
00143 
00144          virtual ~Progress() {}
00145       };
00146 
00148       TCBASE_API bool Copy(const std::string& source, const std::string& dest,
00149          SharedPtr<Progress> copy_status=SharedPtr<Progress>());
00151       TCBASE_API bool Move(const std::string& source, const std::string& dest);
00153       TCBASE_API bool CreateDirectory(const std::string &path);
00155       TCBASE_API bool CreateDirectoryRecursive(const std::string& path);
00156 
00157    } // namespace File
00158 
00163 } // namespace TC
00164 
00165 #endif // _TC_FILE_H_

Copyright (c) Thomas Goessler 2003 - 2008