Fixed: Recursive copy
This commit is contained in:
parent
23b9105803
commit
18b7697a23
2 changed files with 50 additions and 68 deletions
|
@ -63,71 +63,62 @@ bool CFilesCopier::exec()
|
||||||
|
|
||||||
FilesToCopy files;
|
FilesToCopy files;
|
||||||
|
|
||||||
|
// create the list of files to copy
|
||||||
CFilesCopier::getFilesList(files);
|
CFilesCopier::getFilesList(files);
|
||||||
|
|
||||||
|
// copy them
|
||||||
return copyFiles(files);
|
return copyFiles(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CFilesCopier::getFilesList(FilesToCopy &files)
|
void CFilesCopier::getFile(const QFileInfo &fileInfo, const QDir &srcDir, FilesToCopy &files) const
|
||||||
{
|
{
|
||||||
QDir dir(m_sourceDirectory);
|
// full path to file
|
||||||
|
QString fullPath = fileInfo.absoluteFilePath();
|
||||||
|
|
||||||
QFileInfoList entries = dir.entryInfoList(m_includeFilter);
|
// full path where to copy file
|
||||||
|
QString dstPath = m_destinationDirectory + "/" + srcDir.relativeFilePath(fullPath);
|
||||||
|
|
||||||
foreach(const QFileInfo &entry, entries)
|
if (fileInfo.isDir())
|
||||||
{
|
|
||||||
QString fullPath = entry.absoluteFilePath();
|
|
||||||
|
|
||||||
QString dstPath = m_destinationDirectory + "/" + dir.relativeFilePath(fullPath);
|
|
||||||
|
|
||||||
if (entry.isDir())
|
|
||||||
{
|
{
|
||||||
|
// create directory
|
||||||
QDir().mkpath(dstPath);
|
QDir().mkpath(dstPath);
|
||||||
|
|
||||||
QDir subDir(fullPath);
|
QDir subDir(fullPath);
|
||||||
|
|
||||||
QDirIterator it(subDir, QDirIterator::Subdirectories);
|
// get list of all files in directory
|
||||||
|
QFileInfoList entries = subDir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
|
||||||
|
|
||||||
while (it.hasNext())
|
// proces seach file recursively
|
||||||
|
foreach(const QFileInfo &entry, entries)
|
||||||
{
|
{
|
||||||
fullPath = it.next();
|
getFile(entry, srcDir, files);
|
||||||
|
|
||||||
if (it.fileName().startsWith('.')) continue;
|
|
||||||
|
|
||||||
QFileInfo fileInfo = it.fileInfo();
|
|
||||||
|
|
||||||
dstPath = m_destinationDirectory + "/" + dir.relativeFilePath(fullPath);
|
|
||||||
|
|
||||||
if (fileInfo.isDir())
|
|
||||||
{
|
|
||||||
QDir().mkpath(dstPath);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
FileToCopy file;
|
|
||||||
file.filename = it.fileName();
|
|
||||||
file.src = it.filePath();
|
|
||||||
file.dst = dstPath;
|
|
||||||
file.size = it.fileInfo().size();
|
|
||||||
file.date = it.fileInfo().lastModified().toTime_t();
|
|
||||||
file.permissions = it.fileInfo().permissions();
|
|
||||||
|
|
||||||
files << file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
// add the file to list with all useful information
|
||||||
FileToCopy file;
|
FileToCopy file;
|
||||||
file.filename = entry.fileName();
|
file.filename = fileInfo.fileName();
|
||||||
file.src = entry.filePath();
|
file.src = fileInfo.filePath();
|
||||||
file.dst = dstPath;
|
file.dst = dstPath;
|
||||||
file.size = entry.size();
|
file.size = fileInfo.size();
|
||||||
file.date = entry.lastModified().toTime_t();
|
file.date = fileInfo.lastModified().toTime_t();
|
||||||
file.permissions = entry.permissions();
|
file.permissions = fileInfo.permissions();
|
||||||
|
|
||||||
files << file;
|
files << file;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void CFilesCopier::getFilesList(FilesToCopy &files) const
|
||||||
|
{
|
||||||
|
QDir srcDir(m_sourceDirectory);
|
||||||
|
|
||||||
|
// only copy all files from filter
|
||||||
|
QFileInfoList entries = srcDir.entryInfoList(m_includeFilter);
|
||||||
|
|
||||||
|
foreach(const QFileInfo &entry, entries)
|
||||||
|
{
|
||||||
|
getFile(entry, srcDir, files);
|
||||||
}
|
}
|
||||||
|
|
||||||
// copy additional files
|
// copy additional files
|
||||||
|
@ -135,18 +126,7 @@ void CFilesCopier::getFilesList(FilesToCopy &files)
|
||||||
{
|
{
|
||||||
QFileInfo fileInfo(fullpath);
|
QFileInfo fileInfo(fullpath);
|
||||||
|
|
||||||
if (fileInfo.isFile())
|
getFile(fileInfo, srcDir, files);
|
||||||
{
|
|
||||||
FileToCopy file;
|
|
||||||
file.filename = fileInfo.fileName();
|
|
||||||
file.src = fileInfo.filePath();
|
|
||||||
file.dst = m_destinationDirectory + "/" + fileInfo.fileName();
|
|
||||||
file.size = fileInfo.size();
|
|
||||||
file.date = fileInfo.lastModified().toTime_t();
|
|
||||||
file.permissions = fileInfo.permissions();
|
|
||||||
|
|
||||||
files << file;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -54,7 +54,9 @@ protected:
|
||||||
|
|
||||||
typedef QList<FileToCopy> FilesToCopy;
|
typedef QList<FileToCopy> FilesToCopy;
|
||||||
|
|
||||||
void getFilesList(FilesToCopy &files);
|
void getFile(const QFileInfo &info, const QDir &srcDir, FilesToCopy &files) const;
|
||||||
|
void getFilesList(FilesToCopy &files) const;
|
||||||
|
|
||||||
bool copyFiles(const FilesToCopy &files);
|
bool copyFiles(const FilesToCopy &files);
|
||||||
|
|
||||||
IOperationProgressListener *m_listener;
|
IOperationProgressListener *m_listener;
|
||||||
|
|
Loading…
Reference in a new issue