PDA

Ver la Versión Completa : Borra un directorio completo


Emilio
07-06-2006, 02:58:33
Procedimiento que borra una carpeta y su contenido


procedure DelTree(sPath:String);
Var Fich:TSearchRec;
Begin
//Evitamos c:\
If (Length(sPath)=2) And (Right(sPath,1)=':') Then
Exit;
If (Right(sPath,1)<>'\') And (sPath<>'') Then
Try
If FindFirst(sPath+'\*.*',faAnyFile,Fich)=0 Then
Repeat
If (Fich.Attr And faDirectory)>0 Then
Begin
If SLeft(Fich.Name,1)<>'.' Then
DelTree(sPath+'\'+Fich.Name);
End
Else
If Not DelFile(sPath+'\'+Fich.Name) Then
Error('No puedo borrar el fichero '+Fich.Name,0);
Until FindNext(Fich)<>0;
Finally
SysUtils.FindClose(Fich);
RemoveDir(sPath);
End;
End;

Montero
10-10-2007, 23:58:56
Otra vez yop...

En este código me manda el siguiente error:

If (Length(sPath)=2) And (Right(sPath,1)=':') Then

error : Undeclared identifier: 'Right'