Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Algorithmen, Datenstrukturen und Klassendesign (https://www.delphipraxis.net/78-algorithmen-datenstrukturen-und-klassendesign/)
-   -   Löschen von files , by Name Pattern (https://www.delphipraxis.net/190251-loeschen-von-files-name-pattern.html)

bernhard_LA 16. Sep 2016 13:22

Löschen von files , by Name Pattern
 
kann ich mit diesem code

Delphi-Quellcode:
function DeleteFiles(const AFile: string): boolean;
var
   sh: SHFileOpStruct;
begin
   ZeroMemory(@sh, SizeOf(sh));
   with sh do
   begin
     Wnd := Application.Handle;
     wFunc := FO_DELETE;
     pFrom := PChar(AFile +#0);
     fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
   end;
   result := SHFileOperation(sh) = 0;
end;


auch files mit einem Namen Pattern löschen wie
  • DeleteFiles(c:\temp\A*_new.txt');
  • DeleteFiles(c:\temp\A*_B_*new.txt');

Aktuell macht die Funktion nicht so wie ich es will ....

Luckie 16. Sep 2016 13:33

AW: Löschen von files , by Name Pattern
 
Du hast dir die Frage doch schon selbst beantwortet: Nein.

bernhard_LA 16. Sep 2016 13:35

AW: Löschen von files , by Name Pattern
 
gibt es eine einfache Lösung / existierende Lösung ?

Dalai 16. Sep 2016 13:41

AW: Löschen von files , by Name Pattern
 
Also eigentlich sollte das funktionieren, denn MSDN-Library durchsuchenSHFILEOPSTRUCT schreibt für pFrom:
Zitat:

A pointer to one or more source file names. These names should be fully qualified paths to prevent unexpected results.

Standard MS-DOS wildcard characters, such as "*", are permitted only in the file-name position. Using a wildcard character elsewhere in the string will lead to unpredictable results.
Ich würde mal den Rückgabewert der Funktion genauer prüfen, wahrscheinlich gibt das schon einen Hinweis auf das Problem.

Grüße
Dalai

bernhard_LA 16. Sep 2016 13:59

AW: Löschen von files , by Name Pattern
 
Problem gelöst, war ein Fehler in meinem Pattern ...

nahpets 16. Sep 2016 14:24

AW: Löschen von files , by Name Pattern
 
Zitat:

Zitat von bernhard_LA (Beitrag 1347856)
Aktuell macht die Funktion nicht so wie ich es will ....

Was macht sie denn? Überhaupt irgendwas? Oder einfach garnix.

SHFileOperation hat ca. 20 unterschiedliche Rückgabewerte. Du prüfst aber nur, ob kein Fehler aufgetreten ist.

Eventuell fragst Du da ja mal etwas genauer ab, um zu erfahren, was denn da so eventuell schiefgelaufen sein könnte.

https://msdn.microsoft.com/en-us/lib...=vs.85%29.aspx
Delphi-Quellcode:

function DeleteFiles(const AFile: string): boolean;
var
   sh: SHFileOpStruct;
begin
   Result := false;
   ZeroMemory(@sh, SizeOf(sh));
   with sh do
   begin
     Wnd := Application.Handle;
     wFunc := FO_DELETE;
     pFrom := PChar(AFile +#0);
     fFlags := FOF_SILENT or FOF_NOCONFIRMATION;
   end;
   case SHFileOperation(sh) of
     0 : result := True;
     $71 : ShowMessage('The source and destination files are the same file.');
     $72 : ShowMessage('Multiple file paths were specified in the source buffer, but only one destination file path.');
     $73 : ShowMessage('Rename operation was specified but the destination path is a different directory. Use the move operation instead.');
     $74 : ShowMessage('The source is a root directory, which cannot be moved or renamed.');
     $75 : ShowMessage('The operation was canceled by the user, or silently canceled if the appropriate flags were supplied to SHFileOperation.');
     $76 : ShowMessage('The destination is a subtree of the source.');
     $78 : ShowMessage('Security settings denied access to the source.');
     $79 : ShowMessage('The source or destination path exceeded or would exceed MAX_PATH.');
     $7A : ShowMessage('The operation involved multiple destination paths, which can fail in the case of a move operation.');
     $7C : ShowMessage('The path in the source or destination or both was invalid.');
     $7D : ShowMessage('The source and destination have the same parent folder.');
     $7E : ShowMessage('The destination path is an existing file.');
     $80 : ShowMessage('The destination path is an existing folder.');
     $81 : ShowMessage('The name of the file exceeds MAX_PATH.');
     $82 : ShowMessage('The destination is a read-only CD-ROM, possibly unformatted.');
     $83 : ShowMessage('The destination is a read-only DVD, possibly unformatted.');
     $84 : ShowMessage('The destination is a writable CD-ROM, possibly unformatted.');
     $85 : ShowMessage('The file involved in the operation is too large for the destination media or file system.');
     $86 : ShowMessage('The source is a read-only CD-ROM, possibly unformatted.');
     $87 : ShowMessage('The source is a read-only DVD, possibly unformatted.');
     $88 : ShowMessage('The source is a writable CD-ROM, possibly unformatted.');
     $B7 : ShowMessage('MAX_PATH was exceeded during the operation.');
     $402 : ShowMessage('An unknown error occurred. This is typically due to an invalid path in the source or destination. This error does not occur on Windows Vista and later.');
     $10000 : ShowMessage('An unspecified error occurred on the destination.');
     $10074 : ShowMessage('Destination is a root directory and cannot be renamed.');
  end;
end;


Alle Zeitangaben in WEZ +1. Es ist jetzt 20:52 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz