ifrit Master


Registrado: 12 Jun 2007Mensajes: 509Ubicación: La Habana, Cuba
|
Publicado: Mar 02 Nov, 2010 6:22 pm Asunto: RemoveDir en FTP |
|
|
Hola amigos estoy intentando eliminar una carpeta en un ftpo que contenga ficheros y demas dentor, para no hacer la pregunta con las manos vacias me he dedicado a hacer la funcion, pero quiciera saber si saben de alguna mejor funcion o si pueden ver errores o ayudarme algo mas con esta.. Por el momento funciona bien aca les dejo el codigo.
| Código: | // get las folder from ftp path
String getLastFTPDir(String Dir) {
// eliminando el caracter / final
if (Dir[Dir.Length()] == '/')
Dir.Delete(Dir.Length(), 1);
while (Dir.Pos('/') != 0)
Dir = Dir.Delete(1, Dir.Pos('/'));
return Dir;
}
// remove dir
void removeFTPDir(String Dir, TIdFTP *ftp) {
static String iniDir = Dir;
static int counter = 0;
// ir a la carpeta que se va a eliminar
while (Dir.Pos('/') != 0) {
String a = Dir.SubString(1, Dir.Pos('/'));
ftp->ChangeDir(Dir.SubString(1, Dir.Pos('/')));
if (Dir.Pos('/') != Dir.Length()) {
Dir = Dir.Delete(1, Dir.Pos('/'));
}
else {
Dir = Dir.Delete(Dir.Pos('/'), Dir.Length());
}
}
if (Dir.Pos('/') == 0) {
String a = ftp->RetrieveCurrentDir();
if (ftp->RetrieveCurrentDir() == iniDir) {
ftp->ChangeDir(Dir);
}
}
// if (Dir.Pos('/') == 0){
// String a = ftp->RetrieveCurrentDir();
// if (ftp->RetrieveCurrentDir() != (iniDir + Dir)){
// ftp->ChangeDir(Dir);
// iniDir = iniDir + Dir + "/";
// }
// }
// listar
ftp->List("", true);
// obtener si es file or folder
int listCount = ftp->DirectoryListing->Count;
String fileName;
if (listCount > 0) {
for (int i = 0; i <listCount>DirectoryListing->Items[i];
fileName = listItem->FileName;
// file
if (listItem->ItemType == ditFile) {
ftp->Delete(fileName);
if (listCount - 1 == i) {
ftp->ChangeDirUp();
if (counter > 0)
counter--;
Dir = getLastFTPDir(Dir);
removeFTPDir(Dir, ftp);
}
}
else if (listItem->ItemType == ditDirectory) {
counter++;
ftp->ChangeDir(fileName);
Dir = fileName;
removeFTPDir(Dir, ftp);
}
}
} // si no hay elemntos en lista
else if (listCount == 0) {
if (counter > 0) {
ftp->ChangeDirUp();
counter--;
ftp->RemoveDir(Dir);
Dir = getLastFTPDir(ftp->RetrieveCurrentDir());
removeFTPDir(Dir, ftp);
}
else if (counter == 0) {
ftp->ChangeDirUp();
ftp->RemoveDir(Dir);
}
}
} |
_________________ Todos somos ignorantes, lo que no todos ignoramos lo mismo... |
|