Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Problema na função de Deletar Pastas e Arquivos


MagoDanger

Pergunta

Olá amigos, bom dia!

Estou precisando de uma função para deletar todos os arquivos de umas determinada pasta e depois excluir a pasta

Tentei fazer da seguinte forma, porém funciona a parte aonde deleta todos os arquivos de dentro da pasta... MAS, não deleta apasta.

O que estou fazendo de errado,?

** Essa parte FUNCIONA:

var
i: integer;
sr: TSearchRec;

begin
I := FindFirst('\\server\listagem\images\' + DBText1.caption + '\*.*', faAnyFile, SR);
while I = 0 do
begin
  DeleteFile('\\server\listagem\images\' + DBText1.caption + '\' + SR.Name);
  I := FindNext(SR);

Essa parte é a que NÃO funciona:
begin
Windows.RemoveDirectory('\\server\listagem\images\' + DBText1.caption );

end; end; end;

Erro apresentado: Incompatible types: 'String' and "PAnsiChar'

Obrigado, abraços!

Editado por MagoDanger
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

excluir o diretório com todos os arquivos

EX:


unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    OpenDialog1: TOpenDialog;
    procedure Button1Click(Sender: TObject);
    function BrowseForFolder:string;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}
uses ShlObj;

procedure DeleteDir(const DirName: string);
var
  Path: string;
  F: TSearchRec;

begin
  Path:= DirName + '\*.*';
  if FindFirst(Path, faAnyFile, F) = 0 then begin
    try
      repeat
        if (F.Attr and faDirectory <> 0) then begin
          if (F.Name <> '.') and (F.Name <> '..') then begin
            DeleteDir(DirName + '\' + F.Name);
          end;
        end
        else
          DeleteFile(DirName + '\' + F.Name);
      until FindNext(F) <> 0;
    finally
      FindClose(F);
    end;
  end;
  RemoveDir(DirName);
end;

procedure TForm1.Button1Click(Sender: TObject);
var DPath : string;
begin
   Dpath := BrowseForFolder;
   If Dpath <> '' then
   begin
      ShowMessage('O DIRETÓRIO ' + DPath + ' E TODOS OS ARQUIVOS '+#13+#13+
      'SERÃO DELETADOS.');
      DeleteDir(DPath);
   end;
end;

{uses ShlObj}
function TForm1.BrowseForFolder:string;
var
BrowseInfo : TBrowseInfo; {browse info structure for the API function call}
PIDL : PItemIDList; {a PIDL, the storage method for paths used by Shell}
SelectedPath : array[0..MAX_PATH] of Char; {the buffer where the result will be returned}

begin
   Result := '';
   { initialize TBrowseInfo structure to nulls (0) }
   FillChar(BrowseInfo,SizeOf(BrowseInfo),#0);
   BrowseInfo.hwndOwner := Handle; {Form1.Handle, the default}
   BrowseInfo.pszDisplayName := @SelectedPath[0]; {buffer address for API to store result}
   BrowseInfo.lpszTitle := 'Select a folder';
   BrowseInfo.ulFlags := BIF_RETURNONLYFSDIRS; {only file system folders}

   { show the folder browser and return the result to the PIDL itemlist }
   PIDL := SHBrowseForFolder(BrowseInfo);

   { get selected directory from the itemlist and include the full path}
   if Assigned(PIDL) then
      if SHGetPathFromIDList(PIDL, SelectedPath) then
Result := string(SelectedPath);
   end;

end.

end.

abraço

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,8k
×
×
  • Criar Novo...