I learned this function from adrianxw, but it simply skips the names with spaces. What should I do? Is there any other function to do it?
I learned this function from adrianxw, but it simply skips the names with spaces. What should I do? Is there any other function to do it?
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
it will not do that if you give FindFirstFile() the right parameters.
Or, post your code.Code:FindFirstFile("*.*" ...)
obvious questions --
1. what is the purpose of opening the file then closing it right away if open succeeds other than testing if the user running the program has permissions to open file file. Testing for mere existance of the file is unnecessary.
2. is there code somewhere you did not post that calls FindNextFile()?
This program vaerifies the files. It is a file checker. Now I'll give you whole the function.
Code:int checkfiles(char path[], char Folder[][MAXDIRLEN],DWORD index, DWORD &nFolder, DWORD &nBad) { HANDLE hFind; WIN32_FIND_DATA FindData; int ErrorCode; nBad=nFolder=0; bool Continue= true; char fpat[MAXFPATH]=""; ifstream fIn; strcat(path, "\\"); strcpy(fpat,path); strcat(path, "*.*"); for(int i =0;i<index;i++) Folder[i][0]='\0'; // Find the first file hFind = FindFirstFile(path, &FindData); if(hFind == INVALID_HANDLE_VALUE) { ErrorCode = GetLastError(); if (ErrorCode == ERROR_FILE_NOT_FOUND) cout << "There are no files matching that path/mask\n" << endl; else cout << "FindFirstFile() returned error code " << ErrorCode << endl; Continue=false; } else { path[strlen(path)-4]='\0'; if(!(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { strcpy(fpat,path); strcat(fpat,"\\"); strcat(fpat, FindData.cFileName); cout << fpat; fIn.open(fpat); cout.width(5); if(fIn.is_open()){ cout<<cout.fill('.')<< "OK."; fIn.close(); } else{ nBad++; cout<<cout.fill('.')<< "Failed.<<<\a"; } cout<<'\n'; } else{ strcpy(Folder[nFolder], FindData.cFileName); nFolder++; } } if(Continue) { while (FindNextFile(hFind, &FindData) ) { cout<< FindData.cFileName <<endl; if(!(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) { strcpy(fpat,path); strcat(fpat,"\\"); strcat(fpat, FindData.cFileName); cout << fpat; fIn.open(fpat); cout.width(5); if(fIn.is_open()){ fIn.close(); cout<<cout.fill('.')<<"OK."; } else{ nBad++; cout<<cout.fill('.')<< "Failed.<<<\a"; } cout<<'\n'; } else{ if(nFolder < index) { strcpy(Folder[nFolder], FindData.cFileName); nFolder++; } } } ErrorCode = GetLastError(); if (ErrorCode == ERROR_NO_MORE_FILES) cout << endl << "All files checked: "<<nBad<<" files could not be opened!" << endl; else cout << "FindNextFile() returned error code " << ErrorCode << endl; if (!FindClose(hFind)) { ErrorCode = GetLastError(); cout << "FindClose() returned error code " << ErrorCode << endl; } } return ErrorCode; } int main() { INPUT_RECORD InRec; DWORD nFolder[3], nBad, NumRead; char Folder[10][MAXnFOL][MAXDIRLEN]; char path[2][MAXDPATH]={{'\0'}}; cout.width(45); COORD nsize={100,30000}; SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT_HANDLE),nsize); cout <<"--File Tester--"<<endl; cout << "Input Folder Path: " ; cin >> path[0]; checkfiles(path[0], Folder[0],MAXnFOL, nFolder[0],nBad); for(int i=2;i<nFolder[0];i++) { strcpy(path[1],path[0]); strcat(path[1],"\\"); strcat(path[1],Folder[0][i]); cout<<"Checking Sub Directory: "<<path[1]<<"\n\n"; checkfiles(path[1], Folder[1],MAXnFOL, nFolder[1],nBad); } if(nBad>0) cout<<'\a'; cout<<"Press a key to exit..." <<endl; do{ ReadConsoleInput(GetStdHandle(STD_INPUT_HANDLE), &InRec, 1, &NumRead); }while (InRec.EventType != KEY_EVENT); return 0; }
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Please help, I need it.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
Bumping == a bad idea;
Sent from my iPadŽ
I compiled and ran your program using VC++ 6.0 compier. Only problem I found was in the line
the STD_OUTUT _HANDLE has a space in the middle of the macro.Code:SetConsoleScreenBufferSize(GetStdHandle(STD_OUTPUT _HANDLE),nsize);
Otherwise, it runs ok for me, as long as I don't enter any spaces to the initial prompt "Input Folder Path:"
I also had to generate my own values for macros used in your program -- you didn't post them so maybe they are set too small values. I put this at the top of the program, after the includes.
Code:const int MAXDIRLEN = _MAX_PATH; const int MAXFPATH = _MAX_PATH; const int MAXnFOL = 5; const int MAXDPATH = _MAX_PATH;
Code:#define MAXDIRLEN 400 #define MAXFPATH 556 #define MAXDPATH 500 #define MAXnFOL 400It is corrent in mine.the STD_OUTUT _HANDLE has a space in the middle of the macro.
Create a folder with the name "Aa dd" in C: then enter C: in prompt. It wont look at it.
It is not bumping. Dragon told me to send the code, but he didn't gave an answer.Bumping == a bad idea;
Last edited by siavoshkc; 03-02-2006 at 05:17 PM.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C
you are probably missing it on the screen.
Code:--File Tester-- Input Folder Path: c:\temp .. ab cd tempvt.exe c:\temp\tempvt.exe.... OK. All files checked: 0 files could not be opened! Checking Sub Directory: c:\temp\ab cd .. All files checked: 0 files could not be opened! Press a key to exit...
Very confusing. I've done it twice on two seperate machines.
Learn C++ (C++ Books, C Books, FAQ, Forum Search)
Code painter latest version on sourceforge DOWNLOAD NOW!
Download FSB Data Integrity Tester.
Siavosh K C