using support::changeExtension;
using support::compare_ascii_no_case;
using support::contains;
-using support::dirList;
using support::FileName;
using support::getExtension;
using support::libFileSearch;
string const to_base = removeExtension(to.absFilename());
string const to_extension = getExtension(to.absFilename());
- vector<FileName> const files = dirList(FileName(path),
- getExtension(from.absFilename()));
+ vector<FileName> const files = FileName(path).dirList(
+ getExtension(from.absFilename()));
for (vector<FileName>::const_iterator it = files.begin();
it != files.end(); ++it) {
string const from2 = it->absFilename();
}
+std::vector<FileName> FileName::dirList(std::string const & ext)
+{
+ std::vector<FileName> dirlist;
+ if (!exists() || !isDirectory()) {
+ lyxerr << "FileName::dirList(): Directory \"" << absFilename()
+ << "\" does not exist!" << endl;
+ return dirlist;
+ }
+
+ QDir dir(d->fi.absoluteFilePath());
+
+ if (!ext.empty()) {
+ QString filter;
+ switch (ext[0]) {
+ case '.': filter = "*" + toqstr(ext); break;
+ case '*': filter = toqstr(ext); break;
+ default: filter = "*." + toqstr(ext);
+ }
+ dir.setNameFilters(QStringList(filter));
+ LYXERR(Debug::FILES, "FileName::dirList(): filtering on extension "
+ << fromqstr(filter) << " is requested." << endl);
+ }
+
+ QFileInfoList list = dir.entryInfoList();
+ for (int i = 0; i < list.size(); ++i) {
+ FileName fi;
+ fi.d->fi = list.at(i);
+ dirlist.push_back(fi);
+ LYXERR(Debug::FILES, "FileName::dirList(): found file "
+ << fi.absFilename() << endl);
+ }
+
+ return dirlist;
+}
+
+
docstring FileName::displayName(int threshold) const
{
return makeDisplayPath(absFilename(), threshold);
#include "strfwd.h"
-#include <string>
#include <ctime>
+#include <string>
+#include <vector>
namespace lyx {
/// Creates directory. Returns true on success
bool createDirectory(int permissions) const;
+ /// \return list files in a directory having optional extension ext..
+ std::vector<FileName> dirList(
+ std::string const & ext = std::string());
+
/// Get the contents of a file as a huge std::string
std::string fileContents() const;
/**
#endif
-/// Returns a vector of all files in directory dir having extension ext.
-vector<FileName> const dirList(FileName const & dir, string const & ext)
-{
- // EXCEPTIONS FIXME. Rewrite needed when we turn on exceptions. (Lgb)
- vector<FileName> dirlist;
-
- if (!(dir.exists() && dir.isDirectory())) {
- LYXERR(Debug::FILES, "Directory \"" << dir
- << "\" does not exist to DirList.");
- return dirlist;
- }
-
- string extension;
- if (!ext.empty() && ext[0] != '.')
- extension += '.';
- extension += ext;
-
- string const encoded_dir = dir.toFilesystemEncoding();
- fs::directory_iterator dit(encoded_dir);
- fs::directory_iterator end;
- for (; dit != end; ++dit) {
- string const & fil = dit->leaf();
- if (suffixIs(fil, extension))
- dirlist.push_back(FileName::fromFilesystemEncoding(
- encoded_dir + '/' + fil));
- }
- return dirlist;
-}
-
-
// Returns the real name of file name in directory path, with optional
// extension ext.
FileName const fileSearch(string const & path, string const & name,
std::string const & ext = std::string(),
search_mode mode = standard_mode);
-/// Returns a vector of all files in directory dir having extension ext.
-std::vector<FileName> const dirList(FileName const & dir,
- std::string const & ext = std::string());
-
///
bool isLyXFilename(std::string const & filename);