- * Get a FileName from \p name in the encoding used by the file system.
- * Only use this for filenames you got directly from the file system,
- * e.g. from reading a directory.
- * \p name must have an absolute path.
- */
- static FileName const fromFilesystemEncoding(std::string const & name);
-protected:
- /// The absolute file name.
- /// The encoding is currently unspecified, anything else than ASCII
- /// may or may not work.
- std::string name_;
+ * If oldname does not have an extension, it is appended.
+ * If the extension is empty, any extension is removed from the name.
+ */
+ void changeExtension(std::string const & extension);
+
+ static FileName fromFilesystemEncoding(std::string const & name);
+
+ /// get the current working directory
+ static FileName getcwd();
+
+ static FileName tempPath();
+
+ /// filename without path
+ std::string onlyFileName() const;
+ /// filename without path and without extension
+ std::string onlyFileNameWithoutExt() const;
+ /// only extension after the last dot.
+ std::string extension() const;
+ /** checks if the file has the given extension
+ on Windows and Mac it compares case insensitive */
+ bool hasExtension(const std::string & ext);
+ /// path without file name
+ FileName onlyPath() const;
+ /// path of parent directory
+ /// returns empty path for root directory
+ FileName parentPath() const;
+ /// used for display in the Gui
+ docstring displayName(int threshold = 1000) const;
+
+ /// change to a directory, return success
+ bool chdir() const;
+
+ /// \param buffer_path if empty, uses `pwd`
+ docstring const relPath(std::string const & path) const;
+
+ docstring const absoluteFilePath() const;
+
+private:
+ friend bool equivalent(FileName const &, FileName const &);
+ /// Set for tracking of already visited file names.
+ /// Uses operator==() (which may be case insensitive), and not
+ /// equvalent(), so that symlinks are not resolved.
+ typedef std::set<FileName> FileNameSet;
+ /// Helper for public copyTo() to find circular symlink chains
+ bool copyTo(FileName const &, bool, FileNameSet &) const;
+ ///
+ struct Private;
+ Private * const d;