Is there any way in console mode to view the contents of a windows directory?
Also if there is, is there a way to specify only .txt files or .cpp files?
Any help would ge greatly appreciated!
Is there any way in console mode to view the contents of a windows directory?
Also if there is, is there a way to specify only .txt files or .cpp files?
Any help would ge greatly appreciated!
For the whole directory type the path and for just certain files in the current directory specify the extension, like *.txt.Code:#include <stdio.h> #include <stdlib.h> #include <string.h> main(){ char direct[80]; char command[84]; command[0] = 0; printf("What directory? "); gets(direct); strcat(command, "dir "); strcat(command, direct); system(command); }
Code:bool outputDirectory(ostream &outputFile, string &path) { WIN32_FIND_DATA FindFileData; HANDLE hFind; hFind = FindFirstFile(path.c_str(), &FindFileData); if (hFind != INVALID_HANDLE_VALUE) { do { outputFile << FindFileData.cFileName << endl; } while (FindNextFile(hFind, &FindFileData)); } else return 1; FindClose(hFind); return 0; }
Hmm i don't really understand that last part... it works fine, but how do i get it so it only fill find .txt files??Originally posted by Pioneer
For the whole directory type the path and for just certain files in the current directory specify the extension, like *.txt.Code:#include <stdio.h> #include <stdlib.h> #include <string.h> main(){ char direct[80]; char command[84]; command[0] = 0; printf("What directory? "); gets(direct); strcat(command, "dir "); strcat(command, direct); system(command); }
That prints all .txt files from the current working directory. Change it to *.cpp and it'll only print .cpp files.What directory? *.txt
one other things why are the arrays so high?
Okay i got all of that to work...
one more question... instead of displaying all that rubish about the hardrive and date is there a way i can just display them in the following format:
test 44kb
test2 21kb
example 45kb
If there is anything you could let me know i would be very thankful!
anyone??
please let me know if i am being impatient but i really would like to figure this out.
thanks!
>>gets()
Do not use this function. It'll be bad for your system health one day
Calling system() to do a dir is a bad hack, imo.
You should get to know your compiler better and find out what functions it provides to you.
Maybe you could search the boards for previous threads.
>>if i am being impatient
You are, don't bump your threads.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
okay one question then...
i am using borland C++ builder 6 what would i search the help files for?