mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +00:00
Introducing FileName::dirList() to replace the one in filetools.cpp
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@21816 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
623389fdcc
commit
3df451b6d0
@ -47,7 +47,6 @@ using support::bformat;
|
||||
using support::changeExtension;
|
||||
using support::compare_ascii_no_case;
|
||||
using support::contains;
|
||||
using support::dirList;
|
||||
using support::FileName;
|
||||
using support::getExtension;
|
||||
using support::libFileSearch;
|
||||
@ -520,8 +519,8 @@ bool Converters::move(string const & fmt,
|
||||
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();
|
||||
|
@ -285,6 +285,42 @@ bool FileName::createDirectory(int permission) const
|
||||
}
|
||||
|
||||
|
||||
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);
|
||||
|
@ -14,8 +14,9 @@
|
||||
|
||||
#include "strfwd.h"
|
||||
|
||||
#include <string>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace lyx {
|
||||
@ -91,6 +92,10 @@ public:
|
||||
/// 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;
|
||||
/**
|
||||
|
@ -191,36 +191,6 @@ FileName const fileOpenSearch(string const & path, string const & name,
|
||||
#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,
|
||||
|
@ -66,10 +66,6 @@ FileName const fileSearch(std::string const & path,
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user