#pragma warning(disable:4996)
#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include "windows.h"
#include<direct.h>
#include<io.h>
using namespace std;
//移动cal文件到另一个路径
int __stdcall SPIC_SaveCopyCalFileRootPath(char *sPath, char *dPath)
{
HANDLE hFind;
WIN32_FIND_DATA findData;
char sourcePath[MAX_PATH];
char destPath[MAX_PATH];
memset(sourcePath, 0, MAX_PATH);
std::sprintf(sourcePath, "%s\\*", sPath);
TCHAR FileName[MAX_PATH];
memset(FileName, 0, MAX_PATH);
MultiByteToWideChar(CP_ACP, 0, sourcePath, -1, FileName, MAX_PATH);
hFind = FindFirstFile(FileName, &findData);
if (hFind == INVALID_HANDLE_VALUE)
{
return -1;
}
memset(destPath, 0, MAX_PATH);
std::sprintf(destPath, "%s", dPath);
if (access(destPath, 0) == -1) //判断文件夹是否存在,不存在就创建
{
char command[MAX_PATH];
memset(command, 0, MAX_PATH);
std::sprintf(command, "mkdir %s", destPath);
system(command);
if (access(destPath, 0) == -1) //判断文件夹是否存在
{
return -2;
}
}
do
{
if (findData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) // 是否是目录
{
continue;
}
else
{
char name[MAX_PATH];
memset(name, 0, MAX_PATH);
wcstombs(name, findData.cFileName, MAX_PATH);
memset(sourcePath, 0, MAX_PATH);
std::sprintf(sourcePath, "%s\\%s", sPath, name);
memset(destPath, 0, MAX_PATH);
std::sprintf(destPath, "%s\\%s", dPath, name);
wchar_t *wideSource = new wchar_t[MAX_PATH];
MultiByteToWideChar(0, 0, sourcePath, -1, wideSource, MAX_PATH);
wchar_t *wideDest = new wchar_t[MAX_PATH];
MultiByteToWideChar(0, 0, destPath, -1, wideDest, MAX_PATH);
CopyFile(wideSource, wideDest, FALSE); //false代表覆盖,true不覆盖
}
} while (FindNextFile(hFind, &findData));
return 0;
}
void main()
{
while (1)
{
SPIC_SaveCopyCalFileRootPath("D:\\A", "D:\\B");
system("pause");
return;
}
}