progress indicator for file copying

This is a discussion on progress indicator for file copying within the C Programming forums, part of the General Programming Boards category; I am trying to create some sort of progress indicator for file copying. In this program , I had to ...

  1. #1
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765

    progress indicator for file copying

    I am trying to create some sort of progress indicator for file copying.

    In this program, I had to update the progress bar with the symbols after each file copy VIA a gotoxy statement. This got extremely confusing while writting the source code albeit the program turned out fine.

    Now I am working on this route:
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <windows.h>
    
    int FileCopy( char * Fromt, char * To, char * Display );
    int gotoxy(int x, int y);
    int clrscr();
    int kill_cursor(void);
    
    int main()
    {
    	clrscr(0, 0);
    	kill_cursor();
    	FileCopy("d:\\roms\\mameb16\\mk2.zip",
    	"c:\\mk2.zip",
    	"MK2");
    	return 0;
    }
    
    int FileCopy( char * From, char * To, char * Display )
    {
      	size_t len;
      	char buf[BUFSIZ];
     	FILE * in, * out; 
     	FILE * Tmp;
     	if ( ( Tmp = fopen ( From, "r" ) ) == 0 )
     	{
     		printf("%s not found, skipping.\n", Display);
     		Sleep(200);
     	}
     	else
     	{
     		fclose(Tmp);
     		if ( ( in = fopen ( From, "rb" ) ) != NULL ) 
     		{
        			if ( ( out = fopen ( To, "wb" ) ) != NULL ) 
        			{
        				gotoxy(0, 0);
          				printf("Copying..");
          				do 
          				{
            				len = fread ( buf, 1, sizeof buf, in );
            				if ( len != 0 )
            				{
            	  				fwrite ( buf, 1, len, out );
            	  			}
            	  			gotoxy(0, 1);
            				printf("\\");
            				gotoxy(0, 1);
            				printf("|");
            				gotoxy(0, 1);
            				printf("/");
            				gotoxy(0 ,1);
            				printf("-");
          				} 
          				while ( len == sizeof buf );
          				{
          					fclose ( out );
          					gotoxy(0, 1);
          					printf("Copied:  %s\n", Display);
          				}
        			}
        			else
        			{
          				printf("File copy output error:  %s\n", Display);
          			}
        			fclose ( in );
      		}
      		else
      		{
        			printf("File copy input error:  %s\n", Display);
        		}
        	}
      	return EXIT_SUCCESS;
    }
    
    int gotoxy(int x, int y)
    {
    	COORD coord;
       	coord.X = x;
       	coord.Y = y;
       	SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), coord);
    	return 0;
    }
    
    int kill_cursor(void)
    {
    	CONSOLE_CURSOR_INFO cci;
    	cci.dwSize = 1;
    	cci.bVisible = FALSE;
    	SetConsoleCursorInfo( GetStdHandle( STD_OUTPUT_HANDLE ), &cci );
    	return 0;
    }
    
    int clrscr()
    {
        	COORD coordScreen = { 0, 0};
        	DWORD cCharsWritten;
        	CONSOLE_SCREEN_BUFFER_INFO csbi;
        	DWORD dwConSize;
        	HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    
        	GetConsoleScreenBufferInfo(hConsole, &csbi);
        	dwConSize = csbi.dwSize.X * csbi.dwSize.Y;
        	FillConsoleOutputCharacter(hConsole, TEXT(' '), 
        	dwConSize, coordScreen, &cCharsWritten);
        	GetConsoleScreenBufferInfo(hConsole, &csbi);
        	FillConsoleOutputAttribute(hConsole, csbi.wAttributes, 
        	dwConSize, coordScreen, &cCharsWritten);
        	SetConsoleCursorPosition(hConsole, coordScreen);
        	return 0;
    }
    Now, I ran this, and copied a 15mb ( or so ) file, and the little cursor animates perfectly, and the copied message displays perfectly, etc. With one simple file, this does great.

    How would I be able to do something similar to this, or the previous example, with half of the screen already filled with output.

    I was thinking...maybe some fancy, or clever loop or something?
    I want to designate a location on the screen someplace, for a progress indicator throughout the whole program. Yet, in the main section of the screen, I want to be able to display the catagory of files that are being copied, and a confirmation as each individual file is copied.
    Last edited by Shadow; 05-24-2002 at 02:24 PM.
    The world is waiting. I must leave you now.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    You mean print the \|/- on each successive line as you list and copy each file?

    Your copy code is kinda curious - you animate the whole sequence in response to each block of data copied. I was expecting that you would just print the next step in response to each block being copied.

  3. #3
    Unleashed
    Join Date
    Sep 2001
    Posts
    1,765
    [edit]
    grr, this thread is getting too confusing, plus I just realized my fix is still wrong.

    I'm going to let this thread die, rework the code, and post a rigged up example which better explains it.
    [/edit]
    Last edited by Shadow; 05-24-2002 at 02:37 PM.
    The world is waiting. I must leave you now.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Displaying Progress.
    By samus250 in forum C Programming
    Replies: 15
    Last Post: 04-11-2008, 03:56 PM
  2. Creating a progress window
    By Xzyx987X in forum Windows Programming
    Replies: 6
    Last Post: 10-06-2004, 04:02 PM
  3. progress bar newbie
    By WaterNut in forum Windows Programming
    Replies: 18
    Last Post: 08-09-2004, 01:42 PM
  4. Scaling Progress Steps :: MFC
    By kuphryn in forum Windows Programming
    Replies: 0
    Last Post: 11-21-2002, 02:30 PM
  5. Progress Bars
    By knight543 in forum Windows Programming
    Replies: 1
    Last Post: 08-21-2002, 10:45 AM

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