In: Computer Science
C program for copying data from one directory to another using multi threading for linux using command line arrangement.
Program will take two arguments:
1: Source
2: Destination
it will copy all the files from source to destination recursively
Deadline: 4 hours from now.
hello ,
This is function for copy data from one directory to another
#include "snippet.h"
void <miss_class_def>::cpyAllFiles(dirInfo *s, dirInfo
*t)
{
if (dir::exists(t->n) == false)
{
dir::Createdir(t->n);
}
foreach(FileInfo p in s->GetFiles())
{
if (p::dir->n == rootdir)
{
p->cpyTo(Path::Combine(t->ToString(), p->n), true);
FileSize += p->Length;
}
}
// cpy each subdir using recursion.
foreach(dirInfo disSubDir in s->GetDir())
{
dirInfo *nexttSubDir = t->CreateSubdir(disSubDir->n);
//Thr t = new Thr(delegate() { Filecpy(disSubDir, nexttSubDir);
});
//t.Start();
ThreadCon *objCon = new ThreadConr(disSubDir, nexttSubDir);
ThreadStart tempVar(objCon->ThreadFunc);
Thread *objThr = new Thr(&tempVar);
objThr->Start();
CpyAllFiles(disSubDir, nexttSubDir);
delete objThr;
delete objConr;
}
}
return 0;
}
And this is the thread container class :
#include "snippet.h"
ThreadCon::ThreadCon(dirInfo *objs, dirInfo *objt)
{
tsource = objs;
ttarget = objt;
}
void ThreadCon::ThreadFunc()
{
foreach(FileInfo p in ts->GetFiles())
{
p->CpyTo(Path::Combine(ttarget->ToString(), p->n),
true);
}
}