home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1998 May / Pcwk5b98.iso / Borland / Cplus45 / BC45 / IDEHOOK.PAK / PATHSPEC.H < prev    next >
C/C++ Source or Header  |  1995-08-29  |  4KB  |  177 lines

  1. //----------------------------------------------------------------------------
  2. // IdeHook - (C) Copyright 1994 by Borland International
  3. //----------------------------------------------------------------------------
  4. #ifndef __PATHSPEC_H
  5. #define __PATHSPEC_H
  6.  
  7. #ifndef __DIR_H
  8. #  include <dir.h>
  9. #endif
  10.  
  11. //                                                  //
  12. //    class PathSpec for manipulation file paths    //
  13. //                                                  //
  14.  
  15. class PathSpec
  16. {
  17. public:
  18.     //        ctor        //
  19.     
  20.     PathSpec( const char * = "" );
  21.  
  22.     //        accessors            //
  23.     
  24.     const char *    path();
  25.     const char *    drive();
  26.     const char *    dir();
  27.     const char *    file();
  28.     const char *    ext();
  29.  
  30.     void            path(const char *);
  31.     void            drive(const char *);
  32.     void            dir(const char *);
  33.     void            file(const char *);
  34.     void            ext(const char *);
  35.     void            fileext( const char * );
  36.  
  37.     long            age();
  38.  
  39.     //  flags() returns FILENAME, WILDCARDS etc. flags found in dir.h  //
  40.     
  41.     int             flags();
  42.  
  43.     //        explicit splitter/merger    //
  44.     
  45.     int             split();
  46.     void            merge();
  47.  
  48.     //        disk manipulation and polling        //
  49.     
  50.     int             exists();
  51.     int             first();
  52.     int             next();
  53.  
  54.     //        Are this and another PathSpec referring to the same drive? //
  55.     
  56.     int             sameDrive( PathSpec & );
  57.  
  58.     //        Is this PathSpec really representing a directory?           //
  59.     
  60.     int             isDirectory();
  61.  
  62.     void            addTrailingSlash();
  63.     
  64.     //  Strip the trailing slash from the path() element and return  //
  65.     //  the path(). (Calling this invalidates the use dir(), file()  //
  66.     //  and ext()).                                                  //
  67.     
  68.     char *          stripTrailingSlash();
  69.  
  70.     //                                                 //
  71.     //     Do a FileOpen dialog on this pathSpec...    //
  72.     //     'filter' should use the pipe character ('|')//
  73.     //         as a separator                          //
  74.     //         (e.g. "All files (*.*)|*.*|")           //
  75.     //     NOTE: In this implementation 'hwndParent'   //
  76.     //     is a Windows' HWND.                         //
  77.     //                                                 //
  78.     
  79.     int             openFileDialog
  80.                         (
  81.                            const char *    filter = 0,
  82.                            const char *    initialDir = 0,
  83.                            unsigned long   hwndParent = 0
  84.                         );
  85.         
  86.     int             newFileDialog
  87.                         (
  88.                            const char *    filter = 0,
  89.                            const char *    initialDir = 0,
  90.                            unsigned long   hwndParent = 0
  91.                         );
  92.  
  93.     int             fileDialog
  94.                         (
  95.                            const char *    filter = 0,
  96.                            const char *    initialDir = 0,
  97.                            unsigned long   hwndParent = 0,
  98.                            unsigned long   flags = 0
  99.                         );
  100. private:
  101.  
  102.     char _path [ MAXPATH  ];
  103.     char _drive[ MAXDRIVE ];
  104.     char _dir  [ MAXDIR   ];
  105.     char _file [ MAXFILE  ];
  106.     char _ext  [ MAXEXT   ];
  107.     int  _flags;
  108.  
  109.     struct ffblk    _dta;
  110. };
  111.  
  112. inline
  113. PathSpec::PathSpec( const char * apath )
  114. {
  115.     path( apath );
  116. }
  117.  
  118. inline const char *
  119. PathSpec::path()
  120. {
  121.     return( _path );
  122. }
  123.  
  124. inline const char *
  125. PathSpec::drive()
  126. {
  127.     return( _drive );
  128. }
  129.  
  130. inline const char *
  131. PathSpec::dir()
  132. {
  133.     return( _dir );
  134. }
  135.  
  136. inline const char *
  137. PathSpec::file()
  138. {
  139.     return( _file );
  140. }
  141.  
  142. inline const char *
  143. PathSpec::ext()
  144. {
  145.     return( _ext );
  146. }
  147.  
  148. inline int
  149. PathSpec::flags()
  150. {
  151.     return( _flags );
  152. }
  153.  
  154. inline int
  155. PathSpec::exists()
  156. {
  157.     return( first() );
  158. }
  159.  
  160. inline long
  161. PathSpec::age()
  162. {
  163.     if( exists() )
  164.     {
  165.         unsigned long date = _dta.ff_fdate;
  166.         unsigned long time = _dta.ff_ftime;
  167.  
  168.         return( (long)( (date << 16) | time ) );
  169.     }
  170.     return( -1L );
  171. }
  172.  
  173. #endif __PATHSPEC_H
  174.  
  175. // End of file
  176.  
  177.