English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

for writing nc i should copy file from a drive and paste it in other
drive or location .what function i should use for copying a file.
and also for cuting a file.
notice:i am programing in c.

2006-06-28 02:20:03 · 4 answers · asked by vahid_saljooghi 2 in Computers & Internet Programming & Design

4 answers

On UNIX style systems you can execute commands with the system call, for example

system("cp pathname1 pathname2")

Likewise on Windows but with copy instead of cp.

http://www.die.net/doc/linux/man/man3/system.3.html


Windows has a CopyFile function which can be called from C.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/copyfile.asp

2006-06-28 02:31:22 · answer #1 · answered by ymail493 5 · 0 0

Or you can have the program do it with the appropriate calls. Use C file I/O to open the file, write it to another file at the new location, close both. Then make calls to appropriate functions to delete the old files if needed. I beleive that unlink works in *nix and kill works under DOS or DOS box. You'll have to look up the Windows functions if you need it in the Win32 or Win32s APIs. I hope this helps.

2006-06-28 11:15:01 · answer #2 · answered by griz803 5 · 0 0

DanD is quite rignt. One additional detail: you can use function "system" in DOS and Windows also.
system( "copy pathname_1 pathname_2" );
If you want to "cut" the file call then
system( "del pathname_1" ) for Windows
of
system( "rm pathname_1" ) for *NIX

2006-06-28 10:39:26 · answer #3 · answered by alakit013 5 · 0 0

This is not tested and has no real error checking but should get you started.

int copy (char * src, char * dest)
{
char buf[1024];
FILE * in, *out;

in = fopen(src, "r");
if(in == NULL)
{
return(-1);
}

out = fopen(dest,"w");
if(out == NULL)
{
return(-1);
}

while(fread( buf,
sizeof(buf),
1,
in))
{
fwrite(buf,
sizeof(buf),
1,
out);
}
fclose(in);
fclose(out);
return(0);
}

2006-06-28 12:25:15 · answer #4 · answered by Anonymous · 0 0

fedest.com, questions and answers