home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
OS2DEL.ZIP
/
DD.C
next >
Wrap
C/C++ Source or Header
|
1989-11-26
|
8KB
|
264 lines
/* ATKINSON - HOME COMPUTER - 414-543-8929 */
/* CL /AC /G2 KD.C */
#define INCL_DOS
#define INCL_VIO
#include <os2.h>
#include <ctype.h>
typedef char file_names[(100)+1];
typedef file_names inter_arr1[50];
static inter_arr1 dir_array;
typedef file_names inter_arr2[600];
static inter_arr2 file_array;
PSZ pszPath;
PSZ start_dir;
PSZ pszCommandLine;
PSZ change_path;
USHORT cbPath;
USHORT usDisk;
USHORT cbWritten;
USHORT offCommand;
USHORT i;
USHORT cch;
USHORT drive;
USHORT status;
USHORT dir_index;
USHORT dir_maximum;
USHORT file_index;
USHORT file_maximum;
ULONG ulDrives;
SEL selPath;
SEL sel_start_dir;
SEL selEnvironment;
SEL sel_change_path;
main()
{
VioWrtTTY("\r\nDD - Delete Directory - ver 1.00 - OS/2\r\n",43,0);
get_environment();
get_start_dir();
if ((change_path[0] != start_dir[0]) ||
(change_path[1] != start_dir[1]) ||
(change_path[2] != start_dir[2]))
{
usage();
DosExit(EXIT_THREAD,0);
}
status = DosChDir(change_path,0L);
if (status != 0)
{
VioWrtTTY("\r\nDirectory inaccessible\r\n",26,0);
DosExit(EXIT_THREAD,0);
}
delete_dir(change_path);
status = DosChDir(start_dir,0L);
DosExit(EXIT_THREAD,0);
}
delete_dir(dir_to_delete)
PSZ dir_to_delete[100];
{
PSZ delete_dir3;
SEL sel_delete_dir3;
PSZ delete_dir4;
SEL sel_delete_dir4;
USHORT find_result;
HDIR hdir = 0xFFFF;
FILEFINDBUF findbuf;
USHORT usSearchCount = 1;
strcpy(dir_array[(1)], dir_to_delete);
dir_index = 2;
find_result = DosFindFirst("*.*",&hdir,FILE_DIRECTORY,&findbuf,
sizeof(findbuf), &usSearchCount,0L);
while (find_result == 0)
{
if ((findbuf.attrFile & 0x10) == 0x10)
{
if (findbuf.achName[0] == '.')
{
}
else
{
strcpy(dir_array[(dir_index)],dir_to_delete);
strcat(dir_array[(dir_index)],"\\");
strcat(dir_array[(dir_index)],findbuf.achName);
dir_index++;
}
}
find_result = DosFindNext(hdir,&findbuf,sizeof(findbuf),&usSearchCount);
}
dir_maximum = dir_index - 1;
dir_index = 1;
do
{
delete_files(dir_array[(dir_index)]);
dir_index++;
}
while (!(dir_index >= dir_maximum));
status = DosChDir(start_dir, 0L);
for (dir_index = dir_maximum; dir_index >= 1; --dir_index)
{
VioWrtTTY("\r\n",2,0);
VioWrtTTY(dir_array[(dir_index)],strlen(dir_array[(dir_index)]),0);
cbPath = 0;
DosQCurDisk(&usDisk, &ulDrives);
DosQCurDir(usDisk, NULL, &cbPath);
DosAllocSeg(cbPath, &sel_delete_dir3, SEG_NONSHARED);
delete_dir3 = MAKEP(sel_delete_dir3, 0);
DosAllocSeg(100, &sel_delete_dir4, SEG_NONSHARED);
delete_dir4 = MAKEP(sel_delete_dir4, 0);
DosQCurDir(usDisk, delete_dir3, &cbPath);
usDisk = toascii(usDisk+64);
delete_dir4[0] = usDisk;
delete_dir4[1] = '\0';
strcat(delete_dir4,":\\");
strcat(delete_dir4, delete_dir3);
status = DosRmDir(dir_array[(dir_index)],0L);
}
VioWrtTTY("\r\n",2,0);
dir_index++;
}
delete_files(file_name)
file_names file_name;
{
HDIR hdir = 0xFFFF;
FILEFINDBUF findbuf;
USHORT usSearchCount = 1;
USHORT find_result;
PSZ delete_dir1;
SEL sel_delete_dir1;
PSZ delete_dir2;
SEL sel_delete_dir2;
status = DosChDir(start_dir,0L);
status = DosChDir(file_name,0L);
cbPath = 0;
DosQCurDisk(&usDisk, &ulDrives);
DosQCurDir(usDisk, NULL, &cbPath);
DosAllocSeg(cbPath, &sel_delete_dir1, SEG_NONSHARED);
delete_dir1 = MAKEP(sel_delete_dir1, 0);
DosAllocSeg(100, &sel_delete_dir2, SEG_NONSHARED);
delete_dir2 = MAKEP(sel_delete_dir2, 0);
DosQCurDir(usDisk, delete_dir1, &cbPath);
usDisk = toascii(usDisk+64);
delete_dir2[0] = usDisk;
delete_dir2[1] = '\0';
strcat(delete_dir2,":\\");
strcat(delete_dir2, delete_dir1);
file_maximum = 0;
file_index = 1;
find_result = DosFindFirst("*.*",&hdir,FILE_ARCHIVED | FILE_DIRECTORY,
&findbuf, sizeof(findbuf), &usSearchCount,0L);
while (find_result == 0)
{
if (findbuf.achName[0] != '.')
{
strcpy(file_array[(file_index)],delete_dir2);
strcat(file_array[(file_index)],"\\");
strcat(file_array[(file_index)],findbuf.achName);
file_index++;
}
if (file_index > 599)
{
VioWrtTTY("\r\nDelete file limit exceeded...",31,0);
DosExit(EXIT_THREAD,0);
}
find_result = DosFindNext(hdir,&findbuf,sizeof(findbuf),&usSearchCount);
}
file_maximum = file_index - 1;
if (file_maximum > 0)
{
for (file_index = 1; file_index <= file_maximum; ++file_index)
{
delete_file(file_array[(file_index)]);
}
file_index--;
}
}
delete_file(file_name)
file_names file_name;
{
if (strlen(file_name) > 100)
{
VioWrtTTY("\r\nPath too long error",21,0);
DosExit(EXIT_THREAD,0);
}
if ((file_name == ".") || (file_name == ".."))
{
}
else
{
status = DosSetFileMode(file_name,FILE_ARCHIVED,0L);
status = DosDelete(file_name,0L);
if (status != 0)
{
dir_maximum++;
strcpy(dir_array[(dir_maximum)],file_name);
if (dir_maximum > 49)
{
VioWrtTTY("\r\nDelete dir limit exceeded...",30,0);
DosExit(EXIT_THREAD,0);
}
return;
}
}
VioWrtTTY("\r\n",2,0);
VioWrtTTY(file_name,strlen(file_name),0);
}
get_start_dir()
{
cbPath = 0;
DosQCurDisk(&usDisk, &ulDrives);
DosQCurDir(usDisk, NULL, &cbPath);
DosAllocSeg(cbPath, &selPath, SEG_NONSHARED);
pszPath = MAKEP(selPath, 0);
DosAllocSeg(100, &sel_start_dir, SEG_NONSHARED);
start_dir = MAKEP(sel_start_dir, 0);
DosQCurDir(usDisk, pszPath, &cbPath);
usDisk = toascii(usDisk+64);
start_dir[0] = usDisk;
start_dir[1] = '\0';
strcat(start_dir,":\\");
strcat(start_dir, pszPath);
}
get_environment()
{
USHORT i2;
DosGetEnv(&selEnvironment, &offCommand);
pszCommandLine = MAKEP(selEnvironment, offCommand);
for (i = 0; pszCommandLine[i]; i++);
DosAllocSeg(100, &sel_change_path, SEG_NONSHARED);
change_path = MAKEP(sel_change_path, 0);
for (i++, cch = 0; pszCommandLine[cch + i]; cch++);
i++;
for (i2 = 0; i2 < cch; i2++)
{
change_path[i2] = pszCommandLine[i + i2];
}
strupr(change_path);
}
usage()
{
VioWrtTTY("\r\nUsage:",8,0);
VioWrtTTY("\r\n",2,0);
VioWrtTTY("\r\nDD drive:\\path",16,0);
VioWrtTTY("\r\n",2,0);
VioWrtTTY("\r\nEx: DD C:\\SOURCE\\FOO",24,0);
VioWrtTTY("\r\n",2,0);
VioWrtTTY("\r\nEx: DD C:\\FOO",16,0);
VioWrtTTY("\r\n",2,0);
VioWrtTTY("\r\nDesired DIR to delete *must* be on current DISK",49,0);
VioWrtTTY("\r\n",2,0);
VioWrtTTY("\r\nFull DRIVE:\\PATH *must* be given",35,0);
VioWrtTTY("\r\n",2,0);
}