-5

I am trying to make a copy of a file in a folder and I want to write a function to calculate how much of the file remains to be copied.

I can implement it in the terminal with two commands.

The first command will get all files in the folder - before processing

find . -type f | wc -l => counter1 -number of original file

And the second command will get all files already in the folder at current time.

find . -type f | wc -l => counter2 -number of the original file+ its coping

So, file_remaining = counter1 * 2 - counter2

counter1 is multiplied by 2 because I want to make a copy file

How can I make a function to get the information from the two commands in the Ubuntu terminal using C or C++?

4

1 回答 1

0

这是我的回答。如果你不明白我的问题,请不要回答

#include <iostream>
#include<stdio.h>
using namespace std;
   int main( int argc, const char * argv[] )

   {      
         FILE * fp ;
         char tstCommand[] ="find . -type f | wc -l";
         char path[100];
         fp = popen(tstCommand, "r");
         while ( fgets( path, 100, fp ) != NULL )
               cout << path << endl;

         pclose(fp);
         return 0;
   }
于 2013-03-08T04:46:43.290 回答