A
Afifov
Hello All, I have been working on some customized linux commands. I wrote
the command mycpd dir1 dir2 that is supposed to copy a directory to
another. I couldnt debug it in time. But here is wat it does. It reads one
directory recursively, cats the output to a file and then reads that file
(temporary) and call cp for each of its tokens to dir2.
If anyone needs it... check it out. The mycp method is working if u need
it. I can post it.
#include<stdio.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
main(int argc, char *argv[]){
DIR *dir_p;
struct dirent *dir_entry_p;
dir_p= opendir(argv[1]);
FILE *f1 =fopen(argv[2],"w");
if( argv[1]!=NULL && argv[2]!= NULL){
// if(strcmp(argv[1],c1) ==0 && strcmp(argv[2],c2)==0)
while(NULL != (dir_entry_p=readdir(dir_p))){
fprintf(f1,"%s\n",dir_entry_p->d_name);
}
closedir(dir_p);
fclose(f1);
}
else
printf("Illegal Number of Arguments");
FILE *f2 = fopen(argv[2],"r");
char test_string[1000];
char *sub_string;
char c;
int i=0;
while(i<10){
c=getc(f2);
test_string=c;
i++;
}
printf("%s\n",strtok(test_string," "));
while((sub_string=strtok(NULL," "))!=NULL){
printf("%s\n",sub_string);
/*copy each token to location execv("mycp sub_string argv[3]");
while(sub_string !=NULL){
execv("./mycp","sub_string","argv[3]");
i.e. Read the contents of file that displays the content of the directory,
and copy them to lovation argv[3]*/
}
}
the command mycpd dir1 dir2 that is supposed to copy a directory to
another. I couldnt debug it in time. But here is wat it does. It reads one
directory recursively, cats the output to a file and then reads that file
(temporary) and call cp for each of its tokens to dir2.
If anyone needs it... check it out. The mycp method is working if u need
it. I can post it.
#include<stdio.h>
#include <dirent.h>
#include <string.h>
#include <stdlib.h>
main(int argc, char *argv[]){
DIR *dir_p;
struct dirent *dir_entry_p;
dir_p= opendir(argv[1]);
FILE *f1 =fopen(argv[2],"w");
if( argv[1]!=NULL && argv[2]!= NULL){
// if(strcmp(argv[1],c1) ==0 && strcmp(argv[2],c2)==0)
while(NULL != (dir_entry_p=readdir(dir_p))){
fprintf(f1,"%s\n",dir_entry_p->d_name);
}
closedir(dir_p);
fclose(f1);
}
else
printf("Illegal Number of Arguments");
FILE *f2 = fopen(argv[2],"r");
char test_string[1000];
char *sub_string;
char c;
int i=0;
while(i<10){
c=getc(f2);
test_string=c;
i++;
}
printf("%s\n",strtok(test_string," "));
while((sub_string=strtok(NULL," "))!=NULL){
printf("%s\n",sub_string);
/*copy each token to location execv("mycp sub_string argv[3]");
while(sub_string !=NULL){
execv("./mycp","sub_string","argv[3]");
i.e. Read the contents of file that displays the content of the directory,
and copy them to lovation argv[3]*/
}
}