Can you please send us a code example (possibly in C++ Builder) of how I can remove all files of a directory?
Thanks Fabio
			
									
									
						remove all files of a directory
Code: Select all
TStringList *Filelist;
//---------------------------------------------------------------------------
__fastcall TMainForm::TMainForm(TComponent* Owner)
        : TForm(Owner)
{
  Filelist = new TStringList();
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::btDeleteClick(TObject *Sender)
{
  ScSSHClient->Connect();
  ScSFTPClient->Initialize();
  AnsiString Path = "."; //!
  TScSFTPFileHandle Handle;
  Filelist->Clear();
  Handle = ScSFTPClient->OpenDirectory(Path);
  try {
    do {
      ScSFTPClient->ReadDirectory(Handle);
    } while (!ScSFTPClient->EOF);
    for (int i = 0; i Count; i++) {
      AnsiString Filename = Path + "\" + Filelist->Strings[i];
      ScSFTPClient->RemoveFile(Filename);
    }
  }
  __finally {
    ScSFTPClient->CloseHandle(Handle);
  }
}
//---------------------------------------------------------------------------
void __fastcall TMainForm::ScSFTPClientDirectoryList(TObject *Sender,
      const AnsiString Path, const TBytes Handle,
      TScSFTPFileInfo *FileInfo, bool EOF)
{
  if ((FileInfo == NULL) || (FileInfo->Filename == ".") || (FileInfo->Filename == ".."))
    return;
  if ((FileInfo->Longname.Length() == 0) || (FileInfo->Longname.SubString(1,1) != "d"))
    Filelist->Add(FileInfo->Filename);
}
//---------------------------------------------------------------------------- 
				[email protected]
- Posts: 14
- Joined: Mon 21 Jun 2010 13:55
Thanks for the answere, but when I double click to create the event OnDirctoryList, creates this method (C++ version XE2)
void __fastcall ScSFTPClient1DirectoryList(TObject *Sender, const UnicodeString Path, const TArray Handle, TScSFTPFileInfo *FileInfo, bool EOF);
That have arguments different from your example and over all, gives an error "Error in module Form1: Incorrect Method declaration in class Tform1". And if I try to change the arguments as yours the application doesn't stop to the event after the 'ReadDirectory'.
Why?
			
									
									
						void __fastcall ScSFTPClient1DirectoryList(TObject *Sender, const UnicodeString Path, const TArray Handle, TScSFTPFileInfo *FileInfo, bool EOF);
That have arguments different from your example and over all, gives an error "Error in module Form1: Incorrect Method declaration in class Tform1". And if I try to change the arguments as yours the application doesn't stop to the event after the 'ReadDirectory'.
Why?