tim@mentor.cc.purdue.edu (Timothy Lange) (01/03/91)
Several people asked me to make this source available. Since it is useful only on Novell networks and only 103 lines long I thought it best to be posted here. This program, when compiled with the Novell C Interface library, will remove all files and subdirectories from the current drive except for IBMBIO.COM and IBMDOS.COM. It then copies all files from drive/directories named on the command line. Finally it logs out from all Netware file servers. Tim. /* Remove all files from the current directory and subdirectories. Remove subdirectories too. Do not remove any files by the name of IBMBIO.COM and IBMDOS.COM. But will remove COMMAND.COM. Copies files from specified command line directories to current drive. Logout from all Novell file servers. */ #include <dos.h> #include <direct.h> #include <io.h> #include <stdio.h> #include <stdlib.h> #include <novell/nit.h> #include <novell/niterror.h> main(argc, argv) int argc; char *argv[]; { int i; char sys_call[40]; struct find_t find; /* Find first matching file, then find additional matches. */ if(!_dos_findfirst("*.*", _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR | _A_ARCH, &find)) { if (find.attrib & _A_SUBDIR) do_directory(find.name); else remove_file(find.name); } while(!_dos_findnext(&find)) { if (find.attrib & _A_SUBDIR) do_directory(find.name); else remove_file(find.name); } /* Copy files from specified command line directories to hard drive. */ for (i = 2; i <= argc; i++) { strcpy(sys_call, "copy "); strcat(sys_call, argv[i - 1]); system(sys_call); } /* Logout from all Novell file servers. */ logout(); } do_directory(dirname) char dirname[13]; { struct find_t find; if ((strcmp(dirname, ".") != 0) && (strcmp(dirname, "..") != 0)) { /* Change to subdirectory. */ chdir(dirname); /* Find first matching file, then find additional matches. */ if(!_dos_findfirst("*.*", _A_NORMAL | _A_RDONLY | _A_HIDDEN | _A_SYSTEM | _A_SUBDIR | _A_ARCH, &find)) { if (find.attrib & _A_SUBDIR) do_directory(find.name); else remove_file(find.name); } while(!_dos_findnext(&find)) { if (find.attrib & _A_SUBDIR) do_directory(find.name); else remove_file(find.name); } chdir(".."); rmdir(dirname); } } remove_file(file_name) char file_name[13]; { /* Do not remove files with names of IBMBIO.COM and IBMDOS.COM. These are the hidden, system files that boot the machine. Some versions of DOS require that they be in a specific location. */ if ((strcmp(file_name, "IBMBIO.COM") != 0) && (strcmp(file_name, "IBMDOS.COM") != 0)) { _dos_setfileattr(file_name, _A_NORMAL); unlink(file_name); } }