Category : File Managers
Archive   : 0DEL.ZIP
Filename : 0DEL.C

 
Output of file : 0DEL.C contained in archive : 0DEL.ZIP
/**********************************************************************
* Program Id: 0DEL.C *
* Author: Peter M. Perchansky *
* Copyright: (c) Peter M. Perchansky 1989 *
* Purpose: Find and Delete all 0 byte files in a directory *
* Date Written: 08-11-89 *
* Date Modified: *
**********************************************************************/

/**********************************************************************
* Version History *
* *
* Version 1.00 08-11-89 *
**********************************************************************/

/* standard includes */
#include
#include
#include
#include
#include
#include

#define FALSE 0
#define TRUE 1
#define NAME 13 /* current size of find_t name */

int files_deleted = 0; /* gobal - files deleted */
char search_all = FALSE; /* gobal - search all directories flag */

main (int argc, char *argv[])
{
/* function prototypes */
void display_remove_error (char[], char);
void search_directory (char []);
void search_next_directory (char []);
void search_and_delete (char [], char, int);
void print_opening (void);
char *get_specs (int, char *[]);
void print_final_results (void);

char *wild_cards; /* wild cards (if any) supplied by user */

print_opening();
wild_cards = get_specs (argc, argv);
search_directory (wild_cards);

if (search_all)
search_next_directory (wild_cards);

print_final_results ();
exit (0);
}

/* print opening lines */
void print_opening(void)
{
system ("cls");
printf ("\tDelete Zero-Byte Files Utility by Peter M. Perchansky\n");
printf ("\t Copyright (c) Peter M. Perchansky 1989\n\n");
}

/* get wild card specs, set search_all flag, switch to root if requested */
char *get_specs (int argc, char *argv[])
{
static char name[NAME];

if (argc < 2 || argv[1][0] == '/')
strcpy (name, "*.*");
else
strcpy (name, argv[1]);

if (argv[argc -1][0] == '/')
{
strupr (argv[argc - 1]);
if (argv[argc - 1][1] == 'S')
search_all = TRUE;
else
if (argv[argc - 1][1] == 'A')
{
search_all = TRUE;
if ((chdir ("\\")) != 0)
{
printf ("\n\tError changing to root directory.\n");
exit (1);
}
}
}

return name;
}

/* search current directory for matching file specs */
void search_directory (char name[NAME])
{
struct find_t find; /* structure of file directory */

/* Find first matching file, then find additional matches. */
if (!_dos_findfirst (name, 0xffff, &find))
search_and_delete (find.name, find.attrib, find.size);

/* look for all files matching wildcards */
while (!_dos_findnext (&find))
search_and_delete (find.name, find.attrib, find.size);
}

/* search subdirectories for zero byte files to delete */
void search_next_directory (char name[NAME])
{
char *current_dir; /* current directory */
struct find_t find_buffer; /* file info structure */

/* get current directory */
if ((current_dir = getcwd (NULL,0)) == NULL)
{
printf ("\n\tError assigning current directory\n");
exit (1);
}

/* find the first subdirectory in the current directory */
_dos_findfirst ("*.*", _A_SUBDIR, &find_buffer);
if (find_buffer.attrib == _A_SUBDIR && find_buffer.name[0] != '.')
{
if ((chdir (find_buffer.name)) == 0)
printf ("\n\tSwitching to %s directory.\n", find_buffer.name);
else
{
printf ("\n\tError changing to %s directory.\n", find_buffer.name);
exit (1);
}

search_directory (name);
search_next_directory (name);

/* change back to parent directory */
if ( (chdir (current_dir)) != 0)
{
printf ("\n\tError changing back to %s directory.\n", current_dir);
exit (1);
}
}

/* find the next subdirectory */
while (! _dos_findnext (&find_buffer))
if (find_buffer.attrib == _A_SUBDIR && find_buffer.name[0] != '.')
{
if ((chdir (find_buffer.name)) == 0)
printf ("\n\tSearching %s directory.\n", find_buffer.name);
else
{
printf ("\n\tError changing to %s directory.\n", find_buffer.name);
exit (1);
}

search_directory (name);
search_next_directory (name);

/* change back to its parent directory */
if ((chdir (current_dir)) != 0)
{
printf ("\n\tError changing back to %s directory.\n", current_dir);
exit (1);
}
}

free (current_dir);
}

/* search files looking for zero-byte files to delete */
void search_and_delete (char name[NAME], char attrib, int size)
{
if (size == 0) /* is it 0 bytes */
if (!(attrib & _A_SUBDIR)) /* ignore directories */
if (!(attrib & _A_VOLID)) /* ignore volume */
{
if ( (remove (name)) == -1)
display_remove_error (name, attrib);
else
{
printf ("\t%s deleted.\n", name);
files_deleted++;
}
}
}

/* print file attribute on remove error */
void display_remove_error (char name[NAME], char attrib)
{
int known_error = FALSE;

printf ("\n*- Cannot delete %s -*\n", name);

if (attrib & _A_HIDDEN)
{
printf ("\t\t File attribute is hidden.\n");
known_error = TRUE;
}

if (attrib & _A_RDONLY)
{
printf ("\t\t File attribute is read-only.\n");
known_error = TRUE;
}

if (attrib & _A_SYSTEM)
{
printf ("\t\t File attribute is system.\n");
known_error = TRUE;
}

if (!known_error)
printf ("\t\t Unknown error.\n");

printf ("\n");
}

void print_final_results (void)
{
if (!files_deleted)
printf ("\n\tNo zero-byte files were found to delete.\n");
else
printf ("\n\t%d files were deleted.\n", files_deleted);
}


  3 Responses to “Category : File Managers
Archive   : 0DEL.ZIP
Filename : 0DEL.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/