home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 10 Tools
/
10-Tools.zip
/
cenvi23.zip
/
DEL.CMM
< prev
next >
Wrap
Text File
|
1996-01-08
|
3KB
|
116 lines
/*
* del.cmm
*
* CEnvi shell command 'del'. Deletes one or more specified files.
*/
#include "Netware.lib"
usage()
{
printf("Use the DEL command to delete one or more files.\n");
printf("Syntax:\n");
printf(" DEL [drive:][path]filename [/P][/N]\n");
printf("where:\n");
printf(" drive:/path/filename Specifies file(s) to delete. Global file\n");
printf(" name characters * and ? can be used in the\n");
printf(" file name specified.\n");
printf(" /P Prompts for confirmation before deleting\n");
printf(" each file.\n");
printf(" /N Prevents the message \"Are you sure (Y/N)?\"\n");
printf(" from being displayed as files are deleted.\n");
exit(EXIT_FAILURE);
}
/* ---------------------------------------------------------------------- */
dir[0] = "";
it = 1;
prompt = FALSE;
are_you_sure = TRUE;
parse_command_line(argc,argv)
{
for( i=1;i<argc;i++ )
{
if( argv[i][0]=='-' || argv[i][0]=='/' )
{
switch( toupper(argv[i][1]) )
{
default: usage();
case 'P': prompt = TRUE; break;
case 'N': are_you_sure = FALSE; break;
}
} else {
if( it )
{
dir[0] = argv[i]; it = 0;
} else {
dir[GetArraySpan(dir)+1] = argv[i];
}
}
}
}
/* ---------------------------------------------------------------------- */
main(argc,argv)
{
// First thing to do is parse the command line.
num_files = 0;
parse_command_line(argc,argv);
if( it ) Usage();
for( i=0;i<=GetArraySpan(dir);i++ )
{
to_kill = Directory(dir[i]);
if( to_kill==NULL ) continue;
if( GetArraySpan(to_kill)==0 && to_kill[0].attrib & _A_SUBDIR )
{
if( defined(_NWNLM_) )
strcat(dir[i],"/*.*");
else
strcat(dir[i],"\\*.*");
i--;
continue;
}
if( are_you_sure && strstr(dir[i],"*.*") )
{
printf("Delete \"%s\"; Are you sure? (Y/N) ",dir[i]);
ch = getch();
printf("%c\n",ch);
if( toupper(ch)!='Y' ) exit(EXIT_FAILURE);
}
for( i=0;i<=GetArraySpan(to_kill);i++ )
{
if( to_kill[i].attrib & _A_SUBDIR )
{
printf("[Warning] Directory \"%s\" ignored; use DELTREE to delete directories.\n",to_kill[i].name);
continue;
}
if( prompt )
{
printf("Delete file \"%s\"? (Y/N) ",to_kill[i].name);
ch = getch();
printf("%c\n",ch);
if( toupper(ch)!='Y' ) continue;
}
if( remove(to_kill[i].name) )
printf("Unable to delete file \"%s\".\n",to_kill[i].name);
else
num_files ++;
}
}
if( num_files )
{
printf(" %d file(s) deleted\n",num_files);
} else {
printf(" no files deleted\n");
}
}