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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

_rmdir

Status
Not open for further replies.

willi808

Programmer
Jun 11, 2003
14
DE
hi,

i must delete all files under dos (visual studio 1.5).
i use _rmdir but before deleting i must delete all file and i don't know how (without 'system'-instruction because it's a minimized dos version without these instructions).
can someone give a hint...

thanks
 
Hi,
try to use CStdioFile. like the following:

Code:
filepath = "C:\\test.ini"
CStdioFile delFile;
delFile.Remove(filepath);

i hope that it's solve your problem.

brgd
 
thanks

but this is not the solution.
i need it for 16bit under dos. there aren't such things like cstdfile or cfile.

sorry but thanks
 
again Hi,
i think you can use remove function :
Code:
#include <stdio.h>

int main( void )
{
   if( remove( &quot;crt_remove.txt&quot; ) == -1 )
      perror( &quot;Could not delete 'CRT_REMOVE.TXT'&quot; );
   else
      printf( &quot;Deleted 'CRT_REMOVE.TXT'\n&quot; );
}
 
yes i mean this.

but my biggest problem is to remove all files.
because i handle over the path (eg 'f:\progs\test') and then i want delete every file in the path (recursive).

void DelDir(char *argv1, char *argv2)
{
//argv1 is drive (eg 'f')
//argv2 is path (eg 'progs\test')

struct _find_t sfile;
int result;
char buffer[256], buffer2[256];

strcpy(buffer,argv1);
strcat(buffer,&quot;:\\&quot;);
strcat(buffer,argv2);

result = _dos_findfirst(buffer, _A_SUBDIR, &sfile );

while( result == 0 )
{
if(sfile.attrib & _A_NORMAL)
{
strcpy(buffer2,argv2);
strcat(buffer2,&quot;\\&quot;);
strcat(buffer2, sfile.name);

printf(&quot;%s\n&quot;, &buffer2);

_chmod(sfile.name, _S_IWRITE);

strcat(buffer,&quot;\\&quot;);
strcat(buffer,sfile.name);

printf(&quot;%s\n&quot;, &buffer);

remove(buffer2);

DelDir(argv1,buffer);
}

result = _dos_findnext(&sfile);
}
}
 
what is wrong. it don't delete all files from subdirectory how it should...

void DelDir(char *argv1, char *argv2)
{
struct _find_t sfile;
int result;
char buffer[256];

strcpy(buffer,argv1);
strcat(buffer,&quot;:\\&quot;);
strcat(buffer,argv2);

strcat(buffer,&quot;\\*.*&quot;);

result = _dos_findfirst(buffer, _A_NORMAL, &sfile );

while( result == 0 )
{
printf(&quot;%s\n&quot;, &buffer);

_chmod(sfile.name, _S_IWRITE);

if(remove(sfile.name) != -1)
{
printf(&quot;%s delete successful\n&quot;, &sfile.name);
}
else
{
printf(&quot;%s not deleted\n&quot;, &sfile.name);
}

result = _dos_findnext(&sfile);
}
}
 
Hi,
the following program run OK on my pc.
probebly you must go to specific directory(_chdir)
and then delete files.

Code:
#include &quot;stdafx.h&quot;
#include <afx.h>
#include &quot;sys\stat.h&quot;
#include &quot;direct.h&quot;
#include &quot;io.h&quot;
#include &quot;iostream.h&quot;
#include &quot;string.h&quot;

void DelDir(char *, char *);

int main(int argc, char* argv[])
{
  DelDir(&quot;D&quot;,&quot;test&quot;);

  return 0;

}

void DelDir(char *argv1, char *argv2)
{
    struct _finddata_t  sfile;
    int result;
	long hFile;
    char buffer[256];              
    
    strcpy(buffer,argv1);       
    strcat(buffer,&quot;:\\&quot;);       
    strcat(buffer,argv2);

    _chdir(buffer);    
    strcat(buffer,&quot;\\*.*&quot;);

	hFile = _findfirst(buffer, &sfile );
    if(hFile != -1)
    {
      result = 0;
      while( result == 0 )
	  { 
        printf(&quot;%s\n&quot;, &buffer);
        printf(&quot;%s\n&quot;, &sfile.name);
            
        if(_chmod(sfile.name, _S_IWRITE) != -1)
		{
          if(remove(sfile.name) != -1)
            printf(&quot;%s delete successful\n&quot;, &sfile.name);
          else
            printf(&quot;%s not deleted\n&quot;, &sfile.name);
		}
        result = _findnext(hFile,&sfile);            
	  }
      _findclose( hFile );
    }
	else
      printf(&quot;no file founded\n&quot;);

	
}
 
i have also any other question.
if i have a long path name with a lot of files then i get a stack overflow.
what can i do i your mind?
 
path:
f:\eb\ebooks\hacking\anleit~1\sortie~1\alles_~1\anti_t~1\htmlfiles before = 1851
files after = 1076
 
i take the path
test\\f\\eb\\ebooks\\hacking\\anleit~1\\sortie~1\\alles_~1\\anti_t~1\\html
and 2575 files in html.
my program runs succesfull and deletes all files without
Errors.
Maybe you have problem with your Environment Setting.
 
thanks,
the size of my stack wasn't enough...
but when i reach the deepest path it stops deleting!?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top