home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #1
/
monster.zip
/
monster
/
PROG_C
/
SNPD9404.ZIP
/
MV.C
< prev
next >
Wrap
C/C++ Source or Header
|
1994-04-03
|
2KB
|
101 lines
.I 6 3
** modified by Bob Stout, 4 Jun 93
**
** uses file_copy from SNIPPETS file WB_FCOPY.C
.I 9 1
#include <stdlib.h>
.I 24 4
/*
** Tell 'em they messed up
*/
.D 25 3
.I 33 4
/*
** Simple directory test
*/
.I 37 5
/* "Raw" drive specs are always directories */
if (':' == path[1] && '\0' == path[2])
return 1;
.I 41 44
/*
** Use rename or copy and delete
*/
int mv(char *src, char *dest)
{
int errcount = 0;
char buf[FILENAME_MAX];
const char *generr = "ERROR: mv - couldn't %s %s %s\n";
if (':' == dest[1] && *dest != *getcwd(buf, FILENAME_MAX))
{
if (file_copy(src, dest))
{
printf(generr, "move", src, dest);
++errcount;
}
else if (unlink(src))
{
printf(generr, "delete", src, "");
++errcount;
}
}
else
{
if (rename(src, dest))
{
printf(generr, "rename", src, dest);
++errcount;
}
}
return errcount;
}
/*
** Enter here
*/
int main(int argc, char **argv)
{
int src, errcount = 0;
char target[FILENAME_MAX];
puts("mv 1.3 (4 jun 93) - Ray L. McVay/Bob Stout");
.D 42 5
.I 48 5
/*
** Handle cases where target is a directory
*/
.I 52 2
char termch;
.I 53 4
termch = target[strlen(target) - 1];
if ('\\' != termch && ':' != termch)
strcat(target, "\\");
.D 54 1
.I 59 2
errcount += mv(argv[src], target);
.D 60 2
.I 63 5
/*
** Nothing left except 2 explicit file names
*/
.I 64 4
errcount += mv(argv[1], argv[2]);
return errcount;
}
.D 65 6