PDA

View Full Version : DisplayTree Structure of the path



merry
7th February 2007, 11:59
Hi all

Here there is a program [B]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.



#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_StrDestinatio n);

}

void Form1::CopyAllFilesandFolders(QString source,QString destination)
{
QDir dir(source);
QDir dir1;
QString sourceFilePath;
const QFileInfoList * dirs=dir.entryInfoList();
{
if(dirs)

{
QFileInfoListIterator it(*dirs);
QFileInfo * fileInfo;
while(fileInfo=it.current())
{
++it;

if(fileInfo->fileName() =="." || fileInfo->fileName() =="..")
;
else if(fileInfo->isDir())
{
QString destinationFilePath;
destinationFilePath = destination + ("/") + fileInfo->fileName();
dir1.mkdir(destinationFilePath,true);
sourceFilePath = source + ("/") + fileInfo->fileName();
CopyAllFilesandFolders(sourceFilePath,destinationF ilePath);
copy->setText(sourceFilePath);

}

else
{
QString destinationFilePath;
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()
{
m_StrSource = QFileDialog::getExistingDirectory(
"/home",
this,
"get existing directory",
"Choose a directory",
TRUE );

source->setText(m_StrSource);
}

void Form1::SetDestination()
{
m_StrDestination = QFileDialog::getExistingDirectory(
"/home",
this,
"get existing directory",
"Choose a directory",
TRUE );
destination->setText(m_StrDestination);
}

void Form1::ReadNextDir()
{
QApplication * qApp;
qApp->processEvents();
progress->setProgress(++m_totalsteps);

}



Thanx in advance

wysota
1st March 2007, 13:06
Did you manage to solve the problem?

merry
6th March 2007, 11:39
Hi Wysota

Yes my this Problem is Solved

Merry