Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Trying to move files to another directory!

Status
Not open for further replies.

willz99ta

IS-IT--Management
Sep 15, 2004
132
US
Thanks for reading my message,

I am trying to use a filename array (listing all filenames to process) to move files from one directory to another.

I have used the remove command to delete files using C. Is there a similar command to copy or move files to another directory?

Thanks,
Willz99ta
 
No.
It wouldn't be hard though, especially with no error checking.
Code:
void cp(char *arg1, char *arg2) {
FILE *one,*two;
char buf[512];
               one = fopen(arg2,"r");
	       two = fopen(arg1,"a");
	       while ( (fgets(buf,512,one)) != NULL) { 
		       printf("DEBUG: %s",buf);             
	               fputs(buf,two);
                }
		fclose(one);
		fclose(two);
return;
}
 
That's a copy, you'd still need to delete...

There has to be a faster way, because unix copy and unix move are alot different as far as time taken. I can move a file in no time on Linux or any unix (assumin I'm staying on the same physical disk) because it just changes the inode for file and the inodes for the directories in which the file resides...

Howsabout rename...

[plug=shameless]
[/plug]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top