/* move from one file to another */ #include #include #include #include #include #include #include _CRTAPI1 main (c, v) int c; char *v[]; { struct findType fbuf; char src[MAX_PATH], dst[MAX_PATH], name[MAX_PATH]; char *s; int i, erc; char *y; BOOL fExpunge, fDelayUntilReboot; DWORD dwMoveFileFlags; ConvertAppToOem( c, v ); SHIFT (c,v); if (c < 2) { ShowUsage: printf ("Usage: mv [/x [/d]] file1 [ file2 ...] target\n"); printf (" /x dont save deleted files in deleted subdirectory\n"); printf (" /d specifies to delay the rename until the next reboot.\n"); exit (1); } dwMoveFileFlags = MOVEFILE_REPLACE_EXISTING | MOVEFILE_COPY_ALLOWED; fExpunge = FALSE; fDelayUntilReboot = FALSE; for (i=0; i 1 file to another file\n"); exit (1); } erc = 0; for (i=0; i < c-1; i++) { if (rootpath (v[i], src) == -1) { printf ("Cannot move %s - %s\n", v[i], error ()); erc++; continue; } strcpy (name, dst); if (TESTFLAG(fbuf.fbuf.dwFileAttributes, FILE_ATTRIBUTE_DIRECTORY)) { if (!fPathChr (name[strlen(name)-1])) { strcat (name, "\\"); } upd (src, name, name); } if (strcmp (src, name)) { printf ("%s => %s ", src, name); fflush (stdout); if (fExpunge) { if (MoveFileEx( src, dst, dwMoveFileFlags )) { if (dwMoveFileFlags & MOVEFILE_DELAY_UNTIL_REBOOT) printf ("[ok, will happen next reboot]\n"); else printf ("[ok]\n"); } else { printf( "failed - Error Code == %u\n", GetLastError() ); } } else { s = fmove( src, name ); if (s) { erc++; printf ("[%s]\n", s); } else printf ("[ok]\n"); } } else printf ("Source and destination the same, %s\n", src); } return(erc != 0); }