[solved] Copy all files in folder to another directory
-
-
I would iterate on each file in the source directory, get a file, and "copy":http://doc.qt.nokia.com/4.7/qfile.html#copy it on the final path. QFile has also a method remove to delete a file.
-
QDir has also the "file and folder removing functionality":http://doc.qt.nokia.com/4.7/qdir.html#remove (see also rmdir there).
-
Hello
Thank you for your reply! I just tried the following:@QString orgFileName;
foreach (orgFileName, files) // files = qstringlist with file names in folder { QFile tmpFile(folderPath+orgFileName); qDebug() << tmpFile.copy(jPath+orgFileName); qDebug() << "Copy: " << folderPath+"/UI/"+orgFileName << "To: " << jPath+orgFileName; }@
But the copy just returns false... Do I need to open/create some file or... ? Thank you!
Richard -
To remove all files
Qt Code@
QDir directory("C:/DirectoryPath");
QStringList filesList = directory.entryList(QDir::Files);
QString fileName;
foreach(fileName, fileList)
{
if(directory.remove(fileName))
qDebug() << "Removed: " << fileName;
else
qDebug() << "Not removed";
}
@To copy look "Look here for Documentation":http://doc.qt.nokia.com/4.7-snapshot/qfile.html#copy
If you want to over write, you can check whether the file already present in the Directory using
@
QDir dir("filePath");
if(!dir.exists("fileName"))
//copy
@Avoid overwriting, if the file is already there, simply don't copy. If you want to check for File size to see if it is the same file, then "See here":http://doc.qt.nokia.com/4.7-snapshot/qfile.html#size
-