Pessoal, estou com problemas com os comando  DeleteFile e  MoveFile , as vezes
nao deixa mover os arquivos. com a funcao MoverCopiarArquivo tambem ocorre 
isso .

o que pode ser o arquivo nao esta em uso;





         if not CopyFile(PChar(sOrigem), PChar(sDestino), false) then
                   ShowMessage('Erro ao copiar ' + sOrigem + ' para ' + 
sDestino);
               if not DeleteFile(sOrigem) then
                     ShowMessage('Não consegui excluir ' + sOrigem);
               MoveFile(PAnsiChar(PastaPreEnvia + NumNota + '-' + 
EMPRESA.empcod + '-nfe.txt'),
                      PAnsiChar(PastaPreEnvia + 'movidos\' + NumNota + '-' 
+ EMPRESA.empcod + '-nfe.txt'));





function MoverCopiarArquivo(const Origem, Destino : string; Operacao, 
Modo:Integer) : Boolean;
// Requer a unit ShellApi na clausula uses da unit
Const
    Aborted : Boolean = False;
var
   shfo : TSHFileOpStruct;
begin
       FillChar(shfo,SizeOf(shfo),$0);
       with shfo do
       begin

           lpszProgressTitle := 'Aguarde, realizando copia...';
           if Operacao > 2 then
           begin
                operacao := 2;
           end;
           if Modo > 5 then
           begin
               modo := 1;
           end;
           case operacao of
               1: wFunc := FO_MOVE;
               2: wFunc := FO_COPY;
           end;

           case operacao of
               1: lpszProgressTitle := 'mlb - Movendo';
               2: lpszProgressTitle := 'mlb - Copiando';
           end ;

           pFrom := Pchar(Origem);
           pTo := Pchar(Destino);
           case Modo of
               1: fFlags := FOF_SILENT;
               2: fFlags := FOF_ALLOWUNDO or FOF_FILESONLY;  // usar 2
               3: fFlags := FOF_RENAMEONCOLLISION;
               4: fFlags := FOF_NOCONFIRMATION;
               5: fFlags := FOF_SIMPLEPROGRESS;
           end;
       end;
       Result := (SHFileOperation(shfo)= 0) and (not Aborted);
end;

Responder a