Using FindFirstFile
-
I am making a program that copies files with certain file extensions, such as .txt, to other directories that are created by the program. I am having difficulty using FindFirstFile. The problem I am having is selecting the directory and all the files with the .txt extensions. For example, this line of code finds all the txt files in the folder where this program is: hSearch = FindFirstFile(TEXT("*.txt"), &FileData); But, I say I need to get all of the .txt files on my c:\txtfiles directory. What is the correct code to do that? I have tried many things, the one that has worked best is this one. hSearch=FindFirstFile(TEXT("c:\\txtfiles\\*.txt"), &FileData); However with this one if there is more than one txt file in the directory my error will say could not find text files. If I leave just one txt file in the directory it will work. I am just looking for the correct code to copy all txt files from a directory on my c drive. Thanks.
-
I am making a program that copies files with certain file extensions, such as .txt, to other directories that are created by the program. I am having difficulty using FindFirstFile. The problem I am having is selecting the directory and all the files with the .txt extensions. For example, this line of code finds all the txt files in the folder where this program is: hSearch = FindFirstFile(TEXT("*.txt"), &FileData); But, I say I need to get all of the .txt files on my c:\txtfiles directory. What is the correct code to do that? I have tried many things, the one that has worked best is this one. hSearch=FindFirstFile(TEXT("c:\\txtfiles\\*.txt"), &FileData); However with this one if there is more than one txt file in the directory my error will say could not find text files. If I leave just one txt file in the directory it will work. I am just looking for the correct code to copy all txt files from a directory on my c drive. Thanks.
-
I am making a program that copies files with certain file extensions, such as .txt, to other directories that are created by the program. I am having difficulty using FindFirstFile. The problem I am having is selecting the directory and all the files with the .txt extensions. For example, this line of code finds all the txt files in the folder where this program is: hSearch = FindFirstFile(TEXT("*.txt"), &FileData); But, I say I need to get all of the .txt files on my c:\txtfiles directory. What is the correct code to do that? I have tried many things, the one that has worked best is this one. hSearch=FindFirstFile(TEXT("c:\\txtfiles\\*.txt"), &FileData); However with this one if there is more than one txt file in the directory my error will say could not find text files. If I leave just one txt file in the directory it will work. I am just looking for the correct code to copy all txt files from a directory on my c drive. Thanks.
u can try about this: CString szFilePath ,szFileType ,szFileMask ; szFilePath = "c:\\"; szFileType = "*.txt"; szFileMask = szFilePath + szFileType; hFile = FindFirstFile(szFileMask,&FindFileData); while(hFile != INVALID_HANDLE_VALUE) { //do copy operation if(!FindNextFile(hFile,&FindFileData)) break; }