Alle Dateien in einem Verzeichnis löschen



  • Hallo,

    gibt es eine Funktion mit der man alle Dateien in einem Verzeichnis löschen kann ?

    Gruss





  • probier mal das hier. Beispiel für das Löschen aller temporären Druckerfiles (z.B. prnt001.tmp - prnt006.tmp).
    Das Beispiel funzt.

    Gruß

    BOOL CLVErrSimDlg::DeleteAllFiles()
    {
    	CFile del;
    	CFileFind find;
    	CString strFilePath, strCounter;
    	int i = 1;
    	BOOL findStatus = 0;
    	BOOL bBrFlg = 0;
    
    	// erstes temporäres File im Temp Ordner suchen
    	CString strFirstFile;
    	strFirstFile.Format("%d", i);
    	strCounter = "00"+strFirstFile;
    	strFilePath = m_strPathTemp+"\\prnt"+strCounter+".tmp";
    
    	try
    	{
    		findStatus = find.FindFile(strFilePath);				// esrtes temporäres File finden
    		del.Remove(strFilePath);
    		i++;
    	}
    
    	catch(CException* e)
    	{
    		e->ReportError();
    		e->Delete();
    		return 0;
    	}
    
    	// folgende temporäre Files suchen und löschen
    	do
    	{
    		strCounter.Format("%d", i);
    
    		if(i < 10)
    			strCounter = "00"+strCounter;
    		if((i >= 10) && (i < 100))
    			strCounter = "0"+strCounter;
    
    		// das zu löschende File
    		strFilePath = m_strPathTemp+"\\prnt"+strCounter+".tmp";
    
    		if(!findStatus == find.FindFile(strFilePath))				// nächstes temporäres File suchen
    			bBrFlg = 1;
    
    		else
    		{
    			try
    			{
    				del.Remove(strFilePath);						// temporäres File löschen
    				i++;							 // Counter für nächstes File inkrementieren
    			}
    
    			catch(CException* e)
    			{	
    				e->ReportError();
    				e->Delete();
    				return 0;
    			}
    		}
    
    	}
    	while(!bBrFlg);		
    
    return 1;
    }
    

Anmelden zum Antworten