Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find a file with a size of 0, then delete it

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
One of my programs for some reason fills up my C:\ folder with random-named files that are 0 bytes in size. How could I make a simple program to find and delete these files with a size of zero? I need help because I am still learning C++ and haven't got to opening and closing streams and stuff :).
 
#include <io.h>
#include <process.h>
#include <string.h>


void main( void )
{
struct _finddata_t c_file;
long hFile;

/* Find first file in current directory */
if( (hFile = _findfirst( &quot;c:\\folder\\*.*&quot;, &c_file )) != -1L ){
do{
if (c_file.attrib !=_A_SUBDIR && c_file.size == 0){
char szFile[200] = &quot;del c:\\folder\\&quot;;
strcat(szFile,c_file.name);
system(szFile);
}

}while( _findnext( hFile, &c_file ) == 0 );
}

_findclose( hFile );
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top