View Contents of a...

This is a discussion on View Contents of a... within the C++ Programming forums, part of the General Programming Boards category; Is there any way in console mode to view the contents of a windows directory? Also if there is, is ...

  1. #1
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41

    View Contents of a...

    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!

  2. #2
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    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);
    }
    For the whole directory type the path and for just certain files in the current directory specify the extension, like *.txt.

  3. #3
    I lurk
    Join Date
    Aug 2002
    Posts
    1,361
    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;
    }

  4. #4
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    Originally posted by Pioneer
    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);
    }
    For the whole directory type the path and for just certain files in the current directory specify the extension, like *.txt.
    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??

  5. #5
    Registered User Pioneer's Avatar
    Join Date
    Dec 2002
    Posts
    59
    What directory? *.txt
    That prints all .txt files from the current working directory. Change it to *.cpp and it'll only print .cpp files.

  6. #6
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    one other things why are the arrays so high?

  7. #7
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    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!

  8. #8
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    anyone??
    please let me know if i am being impatient but i really would like to figure this out.

    thanks!

  9. #9
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>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]

  10. #10
    Registered User dizz's Avatar
    Join Date
    Nov 2002
    Posts
    41
    okay one question then...
    i am using borland C++ builder 6 what would i search the help files for?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 12:36 PM
  2. buffer contents swapping
    By daluu in forum C++ Programming
    Replies: 7
    Last Post: 10-14-2004, 02:34 PM
  3. Tree View control not appearing
    By Garfield in forum Windows Programming
    Replies: 1
    Last Post: 03-07-2004, 12:47 PM
  4. Set View Position in CEditView :: MFC
    By kuphryn in forum Windows Programming
    Replies: 1
    Last Post: 05-21-2002, 09:27 PM
  5. Determining Active View :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 04-25-2002, 07:34 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21