#include "lightdiroperation.h"
int lc_dir_exists(const char *dirName)
{
WIN32_FIND_DATA wfd;
HANDLE hFind;
if(NULL==dirName)
{
return -1;
}
hFind=FindFirstFile(dirName,&wfd);
if((hFind!=INVALID_HANDLE_VALUE)&&(wfd.dwFileAttributes&FILE_ATTRIBUTE_DIRECTORY))
{
FindClose(hFind);
return 0;
}
FindClose(hFind);
return -1;
}
int lc_dir_create(const char *dirName,int mode)
{
if(NULL==dirName)
{
return -1;
}
if(0==lc_dir_exists(dirName)&&1==mode)
{
return -1;
}
_mkdir(dirName);
return 0;
}
int lc_dir_copy(const char *srcDirName,const char *destDirName,int copyMode)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=NULL;
char *pdir=NULL;
char *pdestdir=NULL;
static int filecount = 0;
if(lc_dir_exists(destDirName)!=0)
{
printf("xxxxxxxxxxxxxxxxxxxxxx\n");
lc_dir_create(pdestdir,0);
}
pdir=(char *)malloc(strlen(srcDirName)+5);
pdestdir=(char *)malloc(strlen(destDirName)+5);
strcpy(pdir,srcDirName);
strcpy(pdestdir,destDirName);
strcat(pdir,"/*");
hFind=FindFirstFile(pdir,&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return 0;
}
free(pdir);
free(pdestdir);
do
{
pdir=(char *)malloc(strlen(srcDirName)+strlen(FindFileData.cFileName)+2);
pdestdir=(char *)malloc(strlen(destDirName)+strlen(FindFileData.cFileName)+2);
sprintf(pdir,"%s\\%s",srcDirName,FindFileData.cFileName);
sprintf(pdestdir,"%s\\%s",destDirName,FindFileData.cFileName);
if(strcmp(FindFileData.cFileName,".")==0||strcmp(FindFileData.cFileName,"..")==0)
{
continue;
}
if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0)
{
filecount++;
printf("%d--------------\n",filecount);
CopyFile(pdir,pdestdir,FALSE);
}
else
{
if(lc_dir_exists(pdestdir)!=0)
{
_mkdir(pdestdir);
}
lc_dir_copy(pdir,pdestdir,1);
}
free(pdir);
free(pdestdir);
}
while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
return 0;
}
int lc_dir_remove(const char *dirName)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=NULL;
char *pdir=NULL;
pdir=(char *)malloc(strlen(dirName)+5);
strcpy(pdir,dirName);
strcat(pdir,"/*");
hFind=FindFirstFile(pdir,&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
{
DeleteFile(dirName);
RemoveDirectory(dirName);
FindClose(hFind);
return 0;
}
free(pdir);
do
{
pdir=(char *)malloc(strlen(dirName)+strlen(FindFileData.cFileName)+2);
sprintf(pdir,"%s\\%s",dirName,FindFileData.cFileName);
printf(pdir);
printf("\n");
if(strcmp(FindFileData.cFileName,".")==0||strcmp(FindFileData.cFileName,"..")==0)
{
RemoveDirectory(pdir);
continue;
}
if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0)
{
DeleteFile(pdir);
}
else
{
lc_dir_remove(pdir);
RemoveDirectory(pdir);
}
free(pdir);
}
while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
if(RemoveDirectory(dirName))
{
return 0;
}
return -1;
}
int lc_is_dots(const char *pszStr)
{
if(strcmp(pszStr,".")!=0&&strcmp(pszStr,"..")!=0)
{
return 0;
}
return -1;
}
int lc_dir_move(const char *pszsrcDirName,const char *pszdestDirName,int moveMode)
{
WIN32_FIND_DATA FindFileData;
HANDLE hFind=NULL;
char *pdir=NULL;
char *pdestdir=NULL;
static int filecount = 0;
pdir=(char *)malloc(strlen(pszsrcDirName)+5);
pdestdir=(char *)malloc(strlen(pszdestDirName)+5);
strcpy(pdir,pszsrcDirName);
strcpy(pdestdir,pszdestDirName);
strcat(pdir,"/*");
hFind=FindFirstFile(pdir,&FindFileData);
if(hFind==INVALID_HANDLE_VALUE)
{
FindClose(hFind);
return 0;
}
free(pdir);
free(pdestdir);
do
{
pdir=(char *)malloc(strlen(pszsrcDirName)+strlen(FindFileData.cFileName)+2);
pdestdir=(char *)malloc(strlen(pszdestDirName)+strlen(FindFileData.cFileName)+2);
sprintf(pdir,"%s\\%s",pszsrcDirName,FindFileData.cFileName);
sprintf(pdestdir,"%s\\%s",pszdestDirName,FindFileData.cFileName);
if(strcmp(FindFileData.cFileName,".")==0||strcmp(FindFileData.cFileName,"..")==0)
{
continue;
}
if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0)
{
filecount++;
printf("%d--------------\n",filecount);
MoveFile(pdir,pdestdir);
}
else
{
if(lc_dir_exists(pdestdir)!=0)
{
_mkdir(pdestdir);
}
lc_dir_move(pdir,pdestdir,1);
}
free(pdir);
free(pdestdir);
}
while(FindNextFile(hFind,&FindFileData));
FindClose(hFind);
lc_dir_remove(pszsrcDirName);
return 0;
}
- 1
- 2
前往页