#include <stdio.h> #include <stdlib.h> #include <windows.h> #include <tchar.h> int main(void) { WIN32_FIND_DATA File; HANDLE hSearch; TCHAR SourcePath[_MAX_PATH]; TCHAR SourceDrive[_MAX_DRIVE]; TCHAR SourceDir[_MAX_DIR]; TCHAR SourceFname[_MAX_FNAME]; TCHAR SourceExt[_MAX_EXT]; TCHAR DestPath[_MAX_PATH]; TCHAR DestDrive[_MAX_DRIVE]; TCHAR DestDir[_MAX_DIR]; LPCTSTR lpszFindPattern = TEXT("D:\\1\\123.txt"); _tsplitpath_s(_T("D:\\1\\"), SourceDrive, _MAX_DRIVE, SourceDir, _MAX_DIR, NULL, 0, NULL, 0); _tsplitpath_s(_T("D:\\2\\"), DestDrive, _MAX_DRIVE, DestDir, _MAX_DIR, NULL, 0, NULL, 0); hSearch = FindFirstFile(lpszFindPattern, &File); if (hSearch != INVALID_HANDLE_VALUE) { do { _tsplitpath_s(File.cFileName, NULL, 0, NULL, 0, SourceFname, _MAX_FNAME, SourceExt, _MAX_EXT); _tmakepath_s(SourcePath, _MAX_PATH, SourceDrive, SourceDir, SourceFname, SourceExt); _tmakepath_s(DestPath, _MAX_PATH, DestDrive, DestDir, SourceFname, SourceExt); BOOL err = CopyFile(SourcePath, DestPath, FALSE); int err1 = GetLastError(); int x = 0; } while (FindNextFile(hSearch, &File)); FindClose(hSearch); } return 0; }
限于文件的复制