home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
C!T ROM 2
/
ctrom_ii_b.zip
/
ctrom_ii_b
/
PROGRAM
/
C
/
DELFREE
/
DELFREE.C
next >
Wrap
Text File
|
1992-10-05
|
6KB
|
162 lines
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
D E L E T E - F R E E
Public Domain Utility by Justin Newman
Auanix Technoligy, INC
The purpose of this program is to delete directories without files
(empty directories) - this file is now placed in the public domain
------------------------------------------------------------------
If you find this program of use (and I do !), please write me some
mail (electronic or postal mail), or send me a small donation:
Justin Newman, Auanix Techoligy, INC
2720 Willamette Street, Suite #106
Eugene, OR 97405
or (electronicly):
Baddude's BBS: 503/688-2860 email user "19"
Billboard BBS: 503/688-2056 email "Holmeboy"
or send me a message through fidonet/netmail.
If you send me a disk and enough to cover postage and handling for
that disk ($1.00 should cover it), I will send you source code for
tons of utilities (by myself, and by many other authors). If you
have any questions, please ask. Thank you. If you make changes &
redistribute this file (and please do), then add to the history.
****** HISTORY: ******************************
October 4th, 1992 Program created, and
- Version 1.00 and released
**********************************************
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include <stdio.h>
#include <string.h>
#include <dir.h>
#ifdef VERSION
#undef VERSION
#endif /* end of "ifdef" */
#define VERSION "1.00" /* the version of the program */
#ifdef RELEASED
#undef RELEASED
#endif /* end of "ifdef" */
#define RELEASED "October 4th, 1992" /* the date this file was released */
#ifdef error /* a macro to print a error message and exit */
#undef error
#endif /* end of "ifdef" */
#define error( s ) printf( "*** \a error: %s ***\n", s );\
exit( 1 ) /* exit out with error number 1 */
#ifdef message /* a macro to print some text */
#undef message
#endif /* end of "ifdef" */
#define message( s ) printf( "%s\n", s ) /* print message */
#ifdef message_n /* a macro to print some text with a number */
#undef message_n
#endif /* end of "ifdef" */
#define message_n( d, s ) printf( "%d %s\n", d, s ) /* print message */
#ifdef banner /* a macro to print our banner, or logon, etc */
#undef banner /* should show modifications, last modder, etc */
#endif /* end of "ifdef" */
#define banner() printf( "DeleteFree version %s, released %s\n", VERSION, RELEASED );\
printf( "\tBy: Justin Newman, Auanix Technoligy, INC\n" );\
printf( "\tPurpose: To delete empty directories\n" );\
printf( "\tSupport: Baddude's BBS - 503/688-2860\n\n" )
int deleted_dirs = 0; /* directories deleted */
int doit( char *path );
/* * * * start of main * * * */
int main( int argc, char *argv[] )
{
char drive[68] = "\0"; /* storage for our search path */
char temp[81]; /* temp storage buffer */
banner(); /* sign in, tell them who we are and what we do */
if( argc >= 2 && argv[1] ) /* did they pass a valid command line? */
strcpy( drive, argv[1] ); /* yes - get path from command line */
else
{
/* tell them they need a path on the command line */
error( "use: delfree [drivename, ie., \"d:\"]" );
}
if( toupper( drive[0] ) > ( setdisk( getdisk() ) + 'A' ) ||
drive[1] != ':' ) /* was that path valid, and does */
{ /* it exist? */
error( "Invalid path on command line" ); /* nope, error */
}
message( "Searching for free directories..." );
message( "---------------------------------" );
doit( drive ); /* start searching and deleting directories */
if( deleted_dirs )
{
message_n( deleted_dirs, "dirs deleted" );
}
else message( "...No directories free" );
return 0;
}
/* * * * start of doit * * * */
int doit( char *path )
{
char search[68], new[68]; /* storage for paths */
int files_in_this_directory = 0; /* files in our directory */
int files = 0; /* files in our child directory we called */
struct ffblk ffblk; /* searching structure declared in <dir.h> */
strcpy( search, path );
strcat( search, "\\*.*" );
if( findfirst( search, &ffblk, 255 ) == 0 ) /* is there any files? */
{
do /* yes, so search for every one, and search through the
directories */
{
/* is this file a directory? and it is not the parent directories
ie. "." or ".." */
if( (ffblk.ff_attrib & 0x10) && *ffblk.ff_name != '.' )
{
strcpy( new, path ); /* make new path */
strcat( new, "\\" );
strcat( new, ffblk.ff_name );
files = doit( new ); /* call doit for the new dir */
if( files == 0 ) /* how many files were found */
{
message( strlwr( new ) );
rmdir( new );
deleted_dirs++;
}
}
/* if not a parent, root, etc,
then increase file counter */
if( *ffblk.ff_name != '.' )
files_in_this_directory++; /* increase the files we found */
}
while( findnext( &ffblk ) == 0 ); /* keep on searching and filling ffblk */
}
/* return the number of files we found to our
parent */
return files_in_this_directory;
}
/* * * * end of file * * * */