Thats easy:
#pragma once
#include <stdio.h>
#include <tchar.h>
#include <windows.h>
class vWalkFs
{
public: virtual int Enter(const TCHAR* full,WIN32_FIND_DATA* fd) = 0;
virtual int Leave(const TCHAR* full,WIN32_FIND_DATA* fd) = 0;
};
unsigned int scopy(TCHAR* dst,const unsigned int cbdst,const unsigned int pos,const TCHAR* src)
{
unsigned int ix,len = _tcslen(src);
if((pos+len)<cbdst)
{
for(ix=0;ix<len;ix++) dst[pos+ix]=src[ix]; dst[pos+ix]=0;
return pos+len;
}
return 0;
}
static void __WalkFs(TCHAR* path,const unsigned int cb,const unsigned int plen,vWalkFs& walk)
{
typedef struct
{
static inline int isdir(WIN32_FIND_DATA& fd)
{
return FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes;
}
static inline int isvalid(WIN32_FIND_DATA& fd)
{
if(!(FILE_ATTRIBUTE_DIRECTORY & fd.dwFileAttributes)) return 2;
if('.'!=fd.cFileName[0]) return 1;
if(0==fd.cFileName[1]) return 0;
if('.'!=fd.cFileName[1]) return 1;
if(0==fd.cFileName[2]) return 0;
return 1;
}
}_;
WIN32_FIND_DATA fd;
HANDLE hf;
unsigned int flen;
scopy(path,cb,plen,__TEXT("\\*.*"));
hf = FindFirstFile(path,&fd);
if(INVALID_HANDLE_VALUE!=hf)
{
do
{
if( _::isvalid(fd) )
{
flen = scopy(path,cb,plen+1,fd.cFileName);
if(walk.Enter(path,&fd))
{
if(_::isdir(fd)) __WalkFs(path,cb,flen,walk);
walk.Leave(path,&fd);
}
}
} while(FindNextFile(hf,&fd));
FindClose(hf);
}
path[plen] = 0;
}
void WalkFs(vWalkFs& walk,const TCHAR* path)
{
TCHAR full[_MAX_PATH+_MAX_FNAME+0x400];
unsigned int cbf = sizeof(full)/sizeof(full[0]);
unsigned int flen = scopy(full,cbf,0,path);
if(flen && ('\\'==full[flen-1])) --flen;
__WalkFs(full,cbf,flen,walk);
}
int _tmain(int argc, _TCHAR* argv[])
{
TCHAR src[0x1000];
if(2<argc)
{
class w : public vWalkFs
{
public: virtual int Enter(const TCHAR* full,WIN32_FIND_DATA* fd)
{
scopy(dst,sizeof(dst)/sizeof(dst[0]),len,full+rel);
if(FILE_ATTRIBUTE_DIRECTORY & fd->dwFileAttributes)
{
CreateDirectory(dst,0);
}
else
{
_tprintf(__TEXT("copy: %s -> %s\r\n"),full,dst);
CopyFile(full,dst,0);
}
return 1;
}
virtual int Leave(const TCHAR* full,WIN32_FIND_DATA* fd)
{
return 1;
}
public:
w(const TCHAR* path)
{
len = scopy(dst,sizeof(dst)/sizeof(dst[0]),0,path);
rel = 0;
CreateDirectory(dst,0);
}
TCHAR dst[0x1000];
unsigned int len;
unsigned int rel;
} walk(argv[2]);
walk.rel = scopy(src,sizeof(src)/sizeof(src[0]),0,argv[1]);
WalkFs(walk,src);
_tprintf(__TEXT("<key>")); _gettch();
}
return 0;
}
Good luck.