DisplayTree Structure of the path
Hi all
Here there is a pr[B]ogram which is copying source to destination but by using this logic i want it displays all the items of the selectedpath in a tree structured form.
Code:
#include <qfiledialog.h>
#include <qstring.h>
#include<qlabel.h>
#include<qstringlist.h>
#include<qprogressbar.h>
#include<qfile.h>
#include<qdir.h>
#include<stdio.h>
#include <qfileinfo.h>
#include<qmessagebox.h>
#include <qapplication.h>
void Form1::init()
{
m_totalsteps= 1;
progress->setTotalSteps(4000);
}
void Form1::copydata()
{
CopyAllFilesandFolders(m_StrSource,m_StrDestination);
}
void Form1
::CopyAllFilesandFolders(QString source,
QString destination
) {
const QFileInfoList * dirs=dir.entryInfoList();
{
if(dirs)
{
QFileInfoListIterator it(*dirs);
while(fileInfo=it.current())
{
++it;
if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
;
else if(fileInfo->isDir())
{
destinationFilePath = destination + ("/") + fileInfo->fileName();
dir1.mkdir(destinationFilePath,true);
sourceFilePath = source + ("/") + fileInfo->fileName();
CopyAllFilesandFolders(sourceFilePath,destinationFilePath);
copy->setText(sourceFilePath);
}
else
{
destinationFilePath = destination+("/")+fileInfo->fileName();
sourceFilePath = source+("/")+fileInfo->fileName();
CopyFiles(sourceFilePath,destinationFilePath);
copy->setText(sourceFilePath);
}
ReadNextDir();
}
}
}
}
bool Form1
::CopyFiles(QString sourceFilePath,
QString destinationFilePath
) {
bool success=false;
QFile srcFile
(sourceFilePath
);
QFile destFile
(destinationFilePath
);
uint dataLength=4096;
char*data = new char[dataLength];
if(srcFile.open(IO_ReadOnly))
{
if(destFile.open(IO_WriteOnly))
{
while(!srcFile.atEnd())
{
memset(data,0*00,dataLength);
int iTotalByteRead=srcFile.readBlock(data,dataLength);
destFile.writeBlock(data,iTotalByteRead);
}
delete data;
destFile.close();
success=true;
}
srcFile.close();
}
return success;
}
void Form1::SetSource()
{
"/home",
this,
"get existing directory",
"Choose a directory",
TRUE );
source->setText(m_StrSource);
}
void Form1::SetDestination()
{
"/home",
this,
"get existing directory",
"Choose a directory",
TRUE );
destination->setText(m_StrDestination);
}
void Form1::ReadNextDir()
{
qApp->processEvents();
progress->setProgress(++m_totalsteps);
}
Thanx in advance
Re: DisplayTree Structure of the path
Did you manage to solve the problem?
Re: DisplayTree Structure of the path
Hi Wysota
Yes my this Problem is Solved
Merry