HelpCopy one file to multiple files with same name

Posts 1–3 of 3 · Page 1 of 1
Copy one file to multiple files with same name
Hey guys.

I'm coding a file manager and I want to open one file and create a x amount of copies from the original file, all those copies in the same directory and name (putting just a counter in the end).

Example of what I want:
Original file: Test.txt
Amount of Copies: 5
Copied Files: Test1.txt, Test2.txt, Test3.txt, Test4.txt, Test5.txt

But I just can do like this:
Original file: Test.txt
Amount of Copies: 5
Copied Files: Test.txt1, Test.txt2, Test.txt3, Test.txt4, Test.txt5

To do the way I'm doing, I'm using sprintf(Filename, "%s%d", argv[3], I);
I've tried using strtok to separate the string using "." as separator, but it gave me Test.1txt as result.

Please, anyone can help me?
Quote Originally Posted by Capevaldo View Post
Hey guys.

I'm coding a file manager and I want to open one file and create a x amount of copies from the original file, all those copies in the same directory and name (putting just a counter in the end).

Example of what I want:
Original file: Test.txt
Amount of Copies: 5
Copied Files: Test1.txt, Test2.txt, Test3.txt, Test4.txt, Test5.txt

But I just can do like this:
Original file: Test.txt
Amount of Copies: 5
Copied Files: Test.txt1, Test.txt2, Test.txt3, Test.txt4, Test.txt5

To do the way I'm doing, I'm using sprintf(Filename, "%s%d", argv[3], I);
I've tried using strtok to separate the string using "." as separator, but it gave me Test.1txt as result.

Please, anyone can help me?
More code please.

what is argv[3]?
Quote Originally Posted by Auxilium View Post


More code please.

what is argv[3]?
Here's my main (its the whole code by now, its still under development)
Code:
int main(int argc, char *argv[]){
	FILE *fpi, *fpo;
	char ch, *op, FileName[500];
	int I = 0, qtd;
	if(argc!=5){
		printf("Numero de argumentos incorreto.\n");
		system("pause");
		exit(-1);
	}
	op = argv[1];
	if(op == NULL){
		printf("Operacao invalida");
		exit(-1);
	}

	fpi=fopen(argv[2], "r");
	if(fpi==NULL){
		printf("Erro ao abrir arquivo\n");
		system("pause");
		exit(-2);
	}

	/*fpo = fopen(argv[3], "w");
	if(fpo == NULL){
		printf("Erro criar arquivo\n");
		system("pause");
		exit(-3);
	}*/

	qtd = atoi(argv[4]);
	do{
		sprintf(FileName, "%s%d", argv[3], I);
		fpo = fopen(FileName, "w");
		if(fpo == NULL){
			printf("Erro criar arquivo\n");
			system("pause");
			exit(-3);
		}

		ch = fgetc(fpi);
		while(!feof(fpi)){
			fputc(ch, fpo);
			ch = fgetc(fpi);
		}
		I++;
		rewind(fpi);
		fclose(fpo);
	}while(I<qtd);
	fclose(fpi);
	system("pause");
	return 0;
}
argv[1] is the operation to be executed ('c' to copy, 'd' to delete, 'j' to join, 's' to split -- i'm not using this right now), argv[2] is the original file location (example: C:/Test.txt), argv[3] is the copy files location (example: C:/TestX.txt -- X is the copy number) and argv[4] is the amount of copies to be created.

The way I'm developing this project is to run by console comand, so the user can type like this: FileManager.exe c C:/Test.txt C:/ 5 and the program should create 5 copies of Text.txt in C:/

(Just ignore the printfs, they are in portuguese ;-; )
Posts 1–3 of 3 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?