[Qt-interest] how to copy the content from one folder to another folder
Prashanth Udupa
prashanthudupa at yahoo.com
Wed Mar 11 12:01:07 CET 2009
I am not sure if Qt has a straight forward function for this. You will need to use a recursive function.. (note I have not tested the function, just wrote it for demonstrating the "how" part. Perhaps you can test it and mail your results to the list?)
bool copyDirectory(const QDir& source, const QDir& dest)
{
QFileInfoList list = source.entryInfoList(QDir::Files|QDir::Dirs|QDir::NoDotAndDotDot);
for(int i=0; i<list.count(); i++)
{
QFileInfo fi = list[i];
if( fi.isFile() )
{
bool success = QFile::copy( fi.absoluteFilePath(), dest.absoluteFilePath(fi.fileName()) );
if(!success)
return false;
}
else
{
QDir s2 = source;
QDir d2 = dest;
bool success = d2.mkdir( fi.fileName() );
if(!success)
return false;
success = s2.cd( fi.fileName() );
if(!success)
return false;
success = copyDirectory( s2, d2 );
if(!success)
return false;
}
}
return true;
}
Hope this helps.
/ Prashanth
________________________________
From: Ravi_Kalepalli <Ravi_Kalepalli at Satyam.com>
To: "qt-interest at trolltech.com" <qt-interest at trolltech.com>
Sent: Wednesday, March 11, 2009 4:20:52 PM
Subject: [Qt-interest] how to copy the content from one folder to another folder
Hi All,
I want to the files from one folder to another folder using QT API’s.
Can anybody please help how to proceed?
QString pic = QFileDialog::getOpenFileName(this,tr("Open Image"), "/C/Data/Images", tr("Image Files (*.png *.jpg *.bmp)"));
I am able to get string of the user selected file in pic. But I am not able to copy another folder(ex: “/C/Data/Pictures” )
Or is there any other approach instead of QFileDialog?
Please help me.
Thanks and Regards
RaviKalepalli
Telephone: 080-66577808
Mobile: 9880724688
________________________________
DISCLAIMER:
This email (including any attachments) is intended for the sole use of the intended recipient/s and may contain material that is CONFIDENTIAL AND PRIVATE COMPANY INFORMATION. Any review or reliance by others or copying or distribution or forwarding of any or all of the contents in this message is STRICTLY PROHIBITED. If you are not the intended recipient, please contact the sender by email and delete all copies; your cooperation in this regard is appreciated.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090311/92cd4804/attachment.html
More information about the Qt-interest-old
mailing list