filename.h 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/filename.h
  3. // Purpose: wxFileName - encapsulates a file path
  4. // Author: Robert Roebling, Vadim Zeitlin
  5. // Modified by:
  6. // Created: 28.12.00
  7. // Copyright: (c) 2000 Robert Roebling
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_FILENAME_H_
  11. #define _WX_FILENAME_H_
  12. #include "wx/arrstr.h"
  13. #include "wx/filefn.h"
  14. #include "wx/datetime.h"
  15. #include "wx/intl.h"
  16. #include "wx/longlong.h"
  17. #include "wx/file.h"
  18. #if wxUSE_FILE
  19. class WXDLLIMPEXP_FWD_BASE wxFile;
  20. #endif
  21. #if wxUSE_FFILE
  22. class WXDLLIMPEXP_FWD_BASE wxFFile;
  23. #endif
  24. // this symbol is defined for the platforms where file systems use volumes in
  25. // paths
  26. #if defined(__WINDOWS__) || defined(__DOS__) || defined(__OS2__)
  27. #define wxHAS_FILESYSTEM_VOLUMES
  28. #endif
  29. // ----------------------------------------------------------------------------
  30. // constants
  31. // ----------------------------------------------------------------------------
  32. // the various values for the path format: this mainly affects the path
  33. // separator but also whether or not the path has the drive part (as under
  34. // Windows)
  35. enum wxPathFormat
  36. {
  37. wxPATH_NATIVE = 0, // the path format for the current platform
  38. wxPATH_UNIX,
  39. wxPATH_BEOS = wxPATH_UNIX,
  40. wxPATH_MAC,
  41. wxPATH_DOS,
  42. wxPATH_WIN = wxPATH_DOS,
  43. wxPATH_OS2 = wxPATH_DOS,
  44. wxPATH_VMS,
  45. wxPATH_MAX // Not a valid value for specifying path format
  46. };
  47. // different conventions that may be used with GetHumanReadableSize()
  48. enum wxSizeConvention
  49. {
  50. wxSIZE_CONV_TRADITIONAL, // 1024 bytes = 1 KB
  51. wxSIZE_CONV_IEC, // 1024 bytes = 1 KiB
  52. wxSIZE_CONV_SI // 1000 bytes = 1 KB
  53. };
  54. // the kind of normalization to do with the file name: these values can be
  55. // or'd together to perform several operations at once
  56. enum wxPathNormalize
  57. {
  58. wxPATH_NORM_ENV_VARS = 0x0001, // replace env vars with their values
  59. wxPATH_NORM_DOTS = 0x0002, // squeeze all .. and .
  60. wxPATH_NORM_TILDE = 0x0004, // Unix only: replace ~ and ~user
  61. wxPATH_NORM_CASE = 0x0008, // if case insensitive => tolower
  62. wxPATH_NORM_ABSOLUTE = 0x0010, // make the path absolute
  63. wxPATH_NORM_LONG = 0x0020, // make the path the long form
  64. wxPATH_NORM_SHORTCUT = 0x0040, // resolve the shortcut, if it is a shortcut
  65. wxPATH_NORM_ALL = 0x00ff & ~wxPATH_NORM_CASE
  66. };
  67. // what exactly should GetPath() return?
  68. enum
  69. {
  70. wxPATH_NO_SEPARATOR = 0x0000, // for symmetry with wxPATH_GET_SEPARATOR
  71. wxPATH_GET_VOLUME = 0x0001, // include the volume if applicable
  72. wxPATH_GET_SEPARATOR = 0x0002 // terminate the path with the separator
  73. };
  74. // Mkdir flags
  75. enum
  76. {
  77. wxPATH_MKDIR_FULL = 0x0001 // create directories recursively
  78. };
  79. // Rmdir flags
  80. enum
  81. {
  82. wxPATH_RMDIR_FULL = 0x0001, // delete with subdirectories if empty
  83. wxPATH_RMDIR_RECURSIVE = 0x0002 // delete all recursively (dangerous!)
  84. };
  85. // FileExists flags
  86. enum
  87. {
  88. wxFILE_EXISTS_REGULAR = 0x0001, // check for existence of a regular file
  89. wxFILE_EXISTS_DIR = 0x0002, // check for existence of a directory
  90. wxFILE_EXISTS_SYMLINK = 0x1004, // check for existence of a symbolic link;
  91. // also sets wxFILE_EXISTS_NO_FOLLOW as
  92. // it would never be satisfied otherwise
  93. wxFILE_EXISTS_DEVICE = 0x0008, // check for existence of a device
  94. wxFILE_EXISTS_FIFO = 0x0016, // check for existence of a FIFO
  95. wxFILE_EXISTS_SOCKET = 0x0032, // check for existence of a socket
  96. // gap for future types
  97. wxFILE_EXISTS_NO_FOLLOW = 0x1000, // don't dereference a contained symlink
  98. wxFILE_EXISTS_ANY = 0x1FFF // check for existence of anything
  99. };
  100. #if wxUSE_LONGLONG
  101. // error code of wxFileName::GetSize()
  102. extern WXDLLIMPEXP_DATA_BASE(const wxULongLong) wxInvalidSize;
  103. #endif // wxUSE_LONGLONG
  104. // ----------------------------------------------------------------------------
  105. // wxFileName: encapsulates a file path
  106. // ----------------------------------------------------------------------------
  107. class WXDLLIMPEXP_BASE wxFileName
  108. {
  109. public:
  110. // constructors and assignment
  111. // the usual stuff
  112. wxFileName() { Clear(); }
  113. wxFileName(const wxFileName& filepath) { Assign(filepath); }
  114. // from a full filename: if it terminates with a '/', a directory path
  115. // is contructed (the name will be empty), otherwise a file name and
  116. // extension are extracted from it
  117. wxFileName( const wxString& fullpath, wxPathFormat format = wxPATH_NATIVE )
  118. { Assign( fullpath, format ); m_dontFollowLinks = false; }
  119. // from a directory name and a file name
  120. wxFileName(const wxString& path,
  121. const wxString& name,
  122. wxPathFormat format = wxPATH_NATIVE)
  123. { Assign(path, name, format); m_dontFollowLinks = false; }
  124. // from a volume, directory name, file base name and extension
  125. wxFileName(const wxString& volume,
  126. const wxString& path,
  127. const wxString& name,
  128. const wxString& ext,
  129. wxPathFormat format = wxPATH_NATIVE)
  130. { Assign(volume, path, name, ext, format); m_dontFollowLinks = false; }
  131. // from a directory name, file base name and extension
  132. wxFileName(const wxString& path,
  133. const wxString& name,
  134. const wxString& ext,
  135. wxPathFormat format = wxPATH_NATIVE)
  136. { Assign(path, name, ext, format); m_dontFollowLinks = false; }
  137. // the same for delayed initialization
  138. void Assign(const wxFileName& filepath);
  139. void Assign(const wxString& fullpath,
  140. wxPathFormat format = wxPATH_NATIVE);
  141. void Assign(const wxString& volume,
  142. const wxString& path,
  143. const wxString& name,
  144. const wxString& ext,
  145. bool hasExt,
  146. wxPathFormat format = wxPATH_NATIVE);
  147. void Assign(const wxString& volume,
  148. const wxString& path,
  149. const wxString& name,
  150. const wxString& ext,
  151. wxPathFormat format = wxPATH_NATIVE)
  152. { Assign(volume, path, name, ext, !ext.empty(), format); }
  153. void Assign(const wxString& path,
  154. const wxString& name,
  155. wxPathFormat format = wxPATH_NATIVE);
  156. void Assign(const wxString& path,
  157. const wxString& name,
  158. const wxString& ext,
  159. wxPathFormat format = wxPATH_NATIVE);
  160. void AssignDir(const wxString& dir, wxPathFormat format = wxPATH_NATIVE);
  161. // assorted assignment operators
  162. wxFileName& operator=(const wxFileName& filename)
  163. { if (this != &filename) Assign(filename); return *this; }
  164. wxFileName& operator=(const wxString& filename)
  165. { Assign(filename); return *this; }
  166. // reset all components to default, uninitialized state
  167. void Clear();
  168. // static pseudo constructors
  169. static wxFileName FileName(const wxString& file,
  170. wxPathFormat format = wxPATH_NATIVE);
  171. static wxFileName DirName(const wxString& dir,
  172. wxPathFormat format = wxPATH_NATIVE);
  173. // file tests
  174. // is the filename valid at all?
  175. bool IsOk() const
  176. {
  177. // we're fine if we have the path or the name or if we're a root dir
  178. return m_dirs.size() != 0 || !m_name.empty() || !m_relative ||
  179. !m_ext.empty() || m_hasExt;
  180. }
  181. // does the file with this name exist?
  182. bool FileExists() const;
  183. static bool FileExists( const wxString &file );
  184. // does the directory with this name exist?
  185. bool DirExists() const;
  186. static bool DirExists( const wxString &dir );
  187. // does anything at all with this name (i.e. file, directory or some
  188. // other file system object such as a device, socket, ...) exist?
  189. bool Exists(int flags = wxFILE_EXISTS_ANY) const;
  190. static bool Exists(const wxString& path, int flags = wxFILE_EXISTS_ANY);
  191. // checks on most common flags for files/directories;
  192. // more platform-specific features (like e.g. Unix permissions) are not
  193. // available in wxFileName
  194. bool IsDirWritable() const { return wxIsWritable(GetPath()); }
  195. static bool IsDirWritable(const wxString &path) { return wxDirExists(path) && wxIsWritable(path); }
  196. bool IsDirReadable() const { return wxIsReadable(GetPath()); }
  197. static bool IsDirReadable(const wxString &path) { return wxDirExists(path) && wxIsReadable(path); }
  198. // NOTE: IsDirExecutable() is not present because the meaning of "executable"
  199. // directory is very platform-dependent and also not so useful
  200. bool IsFileWritable() const { return wxIsWritable(GetFullPath()); }
  201. static bool IsFileWritable(const wxString &path) { return wxFileExists(path) && wxIsWritable(path); }
  202. bool IsFileReadable() const { return wxIsReadable(GetFullPath()); }
  203. static bool IsFileReadable(const wxString &path) { return wxFileExists(path) && wxIsReadable(path); }
  204. bool IsFileExecutable() const { return wxIsExecutable(GetFullPath()); }
  205. static bool IsFileExecutable(const wxString &path) { return wxFileExists(path) && wxIsExecutable(path); }
  206. // set the file permissions to a combination of wxPosixPermissions enum
  207. // values
  208. bool SetPermissions(int permissions);
  209. // time functions
  210. #if wxUSE_DATETIME
  211. // set the file last access/mod and creation times
  212. // (any of the pointers may be NULL)
  213. bool SetTimes(const wxDateTime *dtAccess,
  214. const wxDateTime *dtMod,
  215. const wxDateTime *dtCreate) const;
  216. // set the access and modification times to the current moment
  217. bool Touch() const;
  218. // return the last access, last modification and create times
  219. // (any of the pointers may be NULL)
  220. bool GetTimes(wxDateTime *dtAccess,
  221. wxDateTime *dtMod,
  222. wxDateTime *dtCreate) const;
  223. // convenience wrapper: get just the last mod time of the file
  224. wxDateTime GetModificationTime() const
  225. {
  226. wxDateTime dtMod;
  227. (void)GetTimes(NULL, &dtMod, NULL);
  228. return dtMod;
  229. }
  230. #endif // wxUSE_DATETIME
  231. #if defined( __WXOSX_MAC__ ) && wxOSX_USE_CARBON
  232. bool MacSetTypeAndCreator( wxUint32 type , wxUint32 creator ) ;
  233. bool MacGetTypeAndCreator( wxUint32 *type , wxUint32 *creator ) const;
  234. // gets the 'common' type and creator for a certain extension
  235. static bool MacFindDefaultTypeAndCreator( const wxString& ext , wxUint32 *type , wxUint32 *creator ) ;
  236. // registers application defined extensions and their default type and creator
  237. static void MacRegisterDefaultTypeAndCreator( const wxString& ext , wxUint32 type , wxUint32 creator ) ;
  238. // looks up the appropriate type and creator from the registration and then sets
  239. bool MacSetDefaultTypeAndCreator() ;
  240. #endif
  241. // various file/dir operations
  242. // retrieve the value of the current working directory
  243. void AssignCwd(const wxString& volume = wxEmptyString);
  244. static wxString GetCwd(const wxString& volume = wxEmptyString);
  245. // change the current working directory
  246. bool SetCwd() const;
  247. static bool SetCwd( const wxString &cwd );
  248. // get the value of user home (Unix only mainly)
  249. void AssignHomeDir();
  250. static wxString GetHomeDir();
  251. // get the system temporary directory
  252. static wxString GetTempDir();
  253. #if wxUSE_FILE || wxUSE_FFILE
  254. // get a temp file name starting with the specified prefix
  255. void AssignTempFileName(const wxString& prefix);
  256. static wxString CreateTempFileName(const wxString& prefix);
  257. #endif // wxUSE_FILE
  258. #if wxUSE_FILE
  259. // get a temp file name starting with the specified prefix and open the
  260. // file passed to us using this name for writing (atomically if
  261. // possible)
  262. void AssignTempFileName(const wxString& prefix, wxFile *fileTemp);
  263. static wxString CreateTempFileName(const wxString& prefix,
  264. wxFile *fileTemp);
  265. #endif // wxUSE_FILE
  266. #if wxUSE_FFILE
  267. // get a temp file name starting with the specified prefix and open the
  268. // file passed to us using this name for writing (atomically if
  269. // possible)
  270. void AssignTempFileName(const wxString& prefix, wxFFile *fileTemp);
  271. static wxString CreateTempFileName(const wxString& prefix,
  272. wxFFile *fileTemp);
  273. #endif // wxUSE_FFILE
  274. // directory creation and removal.
  275. bool Mkdir(int perm = wxS_DIR_DEFAULT, int flags = 0) const;
  276. static bool Mkdir(const wxString &dir, int perm = wxS_DIR_DEFAULT,
  277. int flags = 0);
  278. bool Rmdir(int flags = 0) const;
  279. static bool Rmdir(const wxString &dir, int flags = 0);
  280. // operations on the path
  281. // normalize the path: with the default flags value, the path will be
  282. // made absolute, without any ".." and "." and all environment
  283. // variables will be expanded in it
  284. //
  285. // this may be done using another (than current) value of cwd
  286. bool Normalize(int flags = wxPATH_NORM_ALL,
  287. const wxString& cwd = wxEmptyString,
  288. wxPathFormat format = wxPATH_NATIVE);
  289. // get a path path relative to the given base directory, i.e. opposite
  290. // of Normalize
  291. //
  292. // pass an empty string to get a path relative to the working directory
  293. //
  294. // returns true if the file name was modified, false if we failed to do
  295. // anything with it (happens when the file is on a different volume,
  296. // for example)
  297. bool MakeRelativeTo(const wxString& pathBase = wxEmptyString,
  298. wxPathFormat format = wxPATH_NATIVE);
  299. // make the path absolute
  300. //
  301. // this may be done using another (than current) value of cwd
  302. bool MakeAbsolute(const wxString& cwd = wxEmptyString,
  303. wxPathFormat format = wxPATH_NATIVE)
  304. { return Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE |
  305. wxPATH_NORM_TILDE, cwd, format); }
  306. // If the path is a symbolic link (Unix-only), indicate that all
  307. // filesystem operations on this path should be performed on the link
  308. // itself and not on the file it points to, as is the case by default.
  309. //
  310. // No effect if this is not a symbolic link.
  311. void DontFollowLink()
  312. {
  313. m_dontFollowLinks = true;
  314. }
  315. // If the path is a symbolic link (Unix-only), returns whether various
  316. // file operations should act on the link itself, or on its target.
  317. //
  318. // This does not test if the path is really a symlink or not.
  319. bool ShouldFollowLink() const
  320. {
  321. return !m_dontFollowLinks;
  322. }
  323. #if defined(__WIN32__) && !defined(__WXWINCE__) && wxUSE_OLE
  324. // if the path is a shortcut, return the target and optionally,
  325. // the arguments
  326. bool GetShortcutTarget(const wxString& shortcutPath,
  327. wxString& targetFilename,
  328. wxString* arguments = NULL) const;
  329. #endif
  330. #ifndef __WXWINCE__
  331. // if the path contains the value of the environment variable named envname
  332. // then this function replaces it with the string obtained from
  333. // wxString::Format(replacementFmtString, value_of_envname_variable)
  334. //
  335. // Example:
  336. // wxFileName fn("/usr/openwin/lib/someFile");
  337. // fn.ReplaceEnvVariable("OPENWINHOME");
  338. // // now fn.GetFullPath() == "$OPENWINHOME/lib/someFile"
  339. bool ReplaceEnvVariable(const wxString& envname,
  340. const wxString& replacementFmtString = "$%s",
  341. wxPathFormat format = wxPATH_NATIVE);
  342. #endif
  343. // replaces, if present in the path, the home directory for the given user
  344. // (see wxGetHomeDir) with a tilde
  345. bool ReplaceHomeDir(wxPathFormat format = wxPATH_NATIVE);
  346. // Comparison
  347. // compares with the rules of the given platforms format
  348. bool SameAs(const wxFileName& filepath,
  349. wxPathFormat format = wxPATH_NATIVE) const;
  350. // compare with another filename object
  351. bool operator==(const wxFileName& filename) const
  352. { return SameAs(filename); }
  353. bool operator!=(const wxFileName& filename) const
  354. { return !SameAs(filename); }
  355. // compare with a filename string interpreted as a native file name
  356. bool operator==(const wxString& filename) const
  357. { return SameAs(wxFileName(filename)); }
  358. bool operator!=(const wxString& filename) const
  359. { return !SameAs(wxFileName(filename)); }
  360. // are the file names of this type cases sensitive?
  361. static bool IsCaseSensitive( wxPathFormat format = wxPATH_NATIVE );
  362. // is this filename absolute?
  363. bool IsAbsolute(wxPathFormat format = wxPATH_NATIVE) const;
  364. // is this filename relative?
  365. bool IsRelative(wxPathFormat format = wxPATH_NATIVE) const
  366. { return !IsAbsolute(format); }
  367. // Returns the characters that aren't allowed in filenames
  368. // on the specified platform.
  369. static wxString GetForbiddenChars(wxPathFormat format = wxPATH_NATIVE);
  370. // Information about path format
  371. // get the string separating the volume from the path for this format,
  372. // return an empty string if this format doesn't support the notion of
  373. // volumes at all
  374. static wxString GetVolumeSeparator(wxPathFormat format = wxPATH_NATIVE);
  375. // get the string of path separators for this format
  376. static wxString GetPathSeparators(wxPathFormat format = wxPATH_NATIVE);
  377. // get the string of path terminators, i.e. characters which terminate the
  378. // path
  379. static wxString GetPathTerminators(wxPathFormat format = wxPATH_NATIVE);
  380. // get the canonical path separator for this format
  381. static wxUniChar GetPathSeparator(wxPathFormat format = wxPATH_NATIVE)
  382. { return GetPathSeparators(format)[0u]; }
  383. // is the char a path separator for this format?
  384. static bool IsPathSeparator(wxChar ch, wxPathFormat format = wxPATH_NATIVE);
  385. // is this is a DOS path which beings with a windows unique volume name
  386. // ('\\?\Volume{guid}\')?
  387. static bool IsMSWUniqueVolumeNamePath(const wxString& path,
  388. wxPathFormat format = wxPATH_NATIVE);
  389. // Dir accessors
  390. size_t GetDirCount() const { return m_dirs.size(); }
  391. bool AppendDir(const wxString& dir);
  392. void PrependDir(const wxString& dir);
  393. bool InsertDir(size_t before, const wxString& dir);
  394. void RemoveDir(size_t pos);
  395. void RemoveLastDir() { RemoveDir(GetDirCount() - 1); }
  396. // Other accessors
  397. void SetExt( const wxString &ext ) { m_ext = ext; m_hasExt = !m_ext.empty(); }
  398. void ClearExt() { m_ext.clear(); m_hasExt = false; }
  399. void SetEmptyExt() { m_ext.clear(); m_hasExt = true; }
  400. wxString GetExt() const { return m_ext; }
  401. bool HasExt() const { return m_hasExt; }
  402. void SetName( const wxString &name ) { m_name = name; }
  403. wxString GetName() const { return m_name; }
  404. bool HasName() const { return !m_name.empty(); }
  405. void SetVolume( const wxString &volume ) { m_volume = volume; }
  406. wxString GetVolume() const { return m_volume; }
  407. bool HasVolume() const { return !m_volume.empty(); }
  408. // full name is the file name + extension (but without the path)
  409. void SetFullName(const wxString& fullname);
  410. wxString GetFullName() const;
  411. const wxArrayString& GetDirs() const { return m_dirs; }
  412. // flags are combination of wxPATH_GET_XXX flags
  413. wxString GetPath(int flags = wxPATH_GET_VOLUME,
  414. wxPathFormat format = wxPATH_NATIVE) const;
  415. // Replace current path with this one
  416. void SetPath( const wxString &path, wxPathFormat format = wxPATH_NATIVE );
  417. // Construct full path with name and ext
  418. wxString GetFullPath( wxPathFormat format = wxPATH_NATIVE ) const;
  419. // Return the short form of the path (returns identity on non-Windows platforms)
  420. wxString GetShortPath() const;
  421. // Return the long form of the path (returns identity on non-Windows platforms)
  422. wxString GetLongPath() const;
  423. // Is this a file or directory (not necessarily an existing one)
  424. bool IsDir() const { return m_name.empty() && m_ext.empty(); }
  425. // various helpers
  426. // get the canonical path format for this platform
  427. static wxPathFormat GetFormat( wxPathFormat format = wxPATH_NATIVE );
  428. // split a fullpath into the volume, path, (base) name and extension
  429. // (all of the pointers can be NULL)
  430. static void SplitPath(const wxString& fullpath,
  431. wxString *volume,
  432. wxString *path,
  433. wxString *name,
  434. wxString *ext,
  435. bool *hasExt = NULL,
  436. wxPathFormat format = wxPATH_NATIVE);
  437. static void SplitPath(const wxString& fullpath,
  438. wxString *volume,
  439. wxString *path,
  440. wxString *name,
  441. wxString *ext,
  442. wxPathFormat format)
  443. {
  444. SplitPath(fullpath, volume, path, name, ext, NULL, format);
  445. }
  446. // compatibility version: volume is part of path
  447. static void SplitPath(const wxString& fullpath,
  448. wxString *path,
  449. wxString *name,
  450. wxString *ext,
  451. wxPathFormat format = wxPATH_NATIVE);
  452. // split a path into volume and pure path part
  453. static void SplitVolume(const wxString& fullpathWithVolume,
  454. wxString *volume,
  455. wxString *path,
  456. wxPathFormat format = wxPATH_NATIVE);
  457. // strip the file extension: "foo.bar" => "foo" (but ".baz" => ".baz")
  458. static wxString StripExtension(const wxString& fullpath);
  459. #ifdef wxHAS_FILESYSTEM_VOLUMES
  460. // return the string representing a file system volume, or drive
  461. static wxString GetVolumeString(char drive, int flags = wxPATH_GET_SEPARATOR);
  462. #endif // wxHAS_FILESYSTEM_VOLUMES
  463. // File size
  464. #if wxUSE_LONGLONG
  465. // returns the size of the given filename
  466. wxULongLong GetSize() const;
  467. static wxULongLong GetSize(const wxString &file);
  468. // returns the size in a human readable form
  469. wxString
  470. GetHumanReadableSize(const wxString& nullsize = wxGetTranslation("Not available"),
  471. int precision = 1,
  472. wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL) const;
  473. static wxString
  474. GetHumanReadableSize(const wxULongLong& sz,
  475. const wxString& nullsize = wxGetTranslation("Not available"),
  476. int precision = 1,
  477. wxSizeConvention conv = wxSIZE_CONV_TRADITIONAL);
  478. #endif // wxUSE_LONGLONG
  479. // deprecated methods, don't use any more
  480. // --------------------------------------
  481. #ifndef __DIGITALMARS__
  482. wxString GetPath( bool withSep, wxPathFormat format = wxPATH_NATIVE ) const
  483. { return GetPath(withSep ? wxPATH_GET_SEPARATOR : 0, format); }
  484. #endif
  485. wxString GetPathWithSep(wxPathFormat format = wxPATH_NATIVE ) const
  486. { return GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR, format); }
  487. private:
  488. // check whether this dir is valid for Append/Prepend/InsertDir()
  489. static bool IsValidDirComponent(const wxString& dir);
  490. // the drive/volume/device specification (always empty for Unix)
  491. wxString m_volume;
  492. // the path components of the file
  493. wxArrayString m_dirs;
  494. // the file name and extension (empty for directories)
  495. wxString m_name,
  496. m_ext;
  497. // when m_dirs is empty it may mean either that we have no path at all or
  498. // that our path is '/', i.e. the root directory
  499. //
  500. // we use m_relative to distinguish between these two cases, it will be
  501. // true in the former and false in the latter
  502. //
  503. // NB: the path is not absolute just because m_relative is false, it still
  504. // needs the drive (i.e. volume) in some formats (Windows)
  505. bool m_relative;
  506. // when m_ext is empty, it may be because we don't have any extension or
  507. // because we have an empty extension
  508. //
  509. // the difference is important as file with name "foo" and without
  510. // extension has full name "foo" while with empty extension it is "foo."
  511. bool m_hasExt;
  512. // by default, symlinks are dereferenced but this flag can be set with
  513. // DontFollowLink() to change this and make different operations work on
  514. // this file path itself instead of the target of the symlink
  515. bool m_dontFollowLinks;
  516. };
  517. #endif // _WX_FILENAME_H_