Printing Every File

This is a discussion on Printing Every File within the Windows Programming forums, part of the Platform Specific Boards category; i want to print every file of my PC but this code is not searching subfolder(depth value is 2) besides ...

  1. #1
    Registered User
    Join Date
    Feb 2009
    Posts
    11

    Printing Every File

    i want to print every file of my PC
    but this code is not searching subfolder(depth value is 2)
    besides how can i search all drives(C:\,D:\......)one after one using this code...??

    Code:
    #include <stdarg.h>
    #include <stdio.h>
    #include <windows.h>
    #include <string.h>
    
    void Find(char *Path)
    
    {
    	
    
    	char tmpPath[MAX_PATH];
    	char subPath[MAX_PATH];	
    	
    	strcpy(tmpPath, Path);
    	strcat(tmpPath, "\*");
    	
    	WIN32_FIND_DATA FindData;
            HANDLE hFind = FindFirstFile(tmpPath,&FindData);
    	
    	if(hFind == INVALID_HANDLE_VALUE)
            return;
    	
    	
    	
    	do
    	{
    		
    		if(FindData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY && strcmp(FindData.cFileName , ".")!=0 && strcmp(FindData.cFileName , "..")!=0)
    		 {
    			 printf("%s\n", FindData.cFileName);
    		         subPath[strlen(Path) + strlen(FindData.cFileName) + 2];
    			 strcpy(subPath, Path);
                             strcat(subPath, FindData.cFileName);
    			 strcat(subPath, "\\");
    			 strcat(subPath,"*.*");
                             Find(subPath);
    		 }
    		else
    			printf("  %s\n",FindData.cFileName);
    		
    		
    		
    	}while(FindNextFile(hFind,&FindData));  
    	
    	FindClose(hFind);
    	
    	   
    }
    
    int main()
    {
    	
    	Find("C:\\");
    
    	
    }

  2. #2
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    1,534
    Something I noticed right off the bat
    Code:
    strcat(tmpPath, "\*");
    should be
    Code:
    strcat(tmpPath, "\\*");
    and
    Code:
    Find("C:\\");
    should be
    Code:
    Find("C:");
    As for enumerating files in different volumes, use the GetLogicalDriveStrings() function.
    A class that doesn't overload all operators just isn't finished yet. -- SmugCeePlusPlusWeenie
    A year spent in artificial intelligence is enough to make one believe in God. -- Alan J. Perlis

  3. #3
    Registered User
    Join Date
    Feb 2009
    Posts
    11

    " strcat(tmpPath, "\\*"); "does not work at all

  4. #4
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Well, it would have to work better, as "\*" is illegal.

    What do you want the line
    Code:
    subPath[strlen(Path) + strlen(FindData.cFileName) + 2];
    to do? Because right now it does pretty much nothing.

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    11

    yes.i have got it
    "subPath[strlen(Path) + strlen(FindData.cFileName) + 2];"it has no use
    but using "\*" shows much file than using "\\*"... i am confused
    still this code can't open some folder
    such as this can not open the subdirectories of Program File in C:\ drive

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Looking at it again, either you want "C:" and "\\*" (to get C:\*) or you want "C:\\" and "*" (also to get C:\*) -- right now you have "C:\\" and "\\*" which gives C:\\* which is probably not much of a path.

    You also I would think need to get rid of the * at the end of the path before you tack on a directory name.

  7. #7
    Registered User
    Join Date
    Feb 2009
    Posts
    11
    i have fixed it
    how can i use GetLogicalDriveStrings() this function?

  8. #8
    Registered User carrotcake1029's Avatar
    Join Date
    Apr 2008
    Posts
    398
    http://lmgtfy.com/?q=GetLogicalDriveStrings
    First link, msdn link, which is always useful.
    Second link has an implementation.

  9. #9
    Registered User
    Join Date
    Feb 2009
    Posts
    11
    will anyone say what does this line mean in this code...???

    strcat(tmpPath, "\\*");

    and

    if(FindData.cFileName[0]=='.') //what does this line mean??
    return;

    and what is the difference between this two lines:
    strcat(tmpPath, "\\*");
    strcat(tmpPath, "*.*");



    thanks in advance.
    Last edited by maruf10; 03-16-2009 at 10:47 AM.

  10. #10
    Captain Crash brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,160
    Quote Originally Posted by maruf10 View Post
    i want to print every file of my PC
    You are going to need a lot of paper
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  2. gcc link external library
    By spank in forum C Programming
    Replies: 6
    Last Post: 08-08-2007, 03:44 PM
  3. Inventory records
    By jsbeckton in forum C Programming
    Replies: 23
    Last Post: 06-28-2007, 04:14 AM
  4. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM
  5. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 04:10 PM

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