AGB  ·  Datenschutz  ·  Impressum  







Anmelden
Nützliche Links
Registrieren
Thema durchsuchen
Ansicht
Themen-Optionen

Löschen von files , by Name Pattern

Ein Thema von bernhard_LA · begonnen am 16. Sep 2016 · letzter Beitrag vom 16. Sep 2016
Antwort Antwort
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.121 Beiträge
 
Delphi 11 Alexandria
 
#1

Löschen von files , by Name Pattern

  Alt 16. Sep 2016, 13:22
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 ....
  Mit Zitat antworten Zitat
Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#2

AW: Löschen von files , by Name Pattern

  Alt 16. Sep 2016, 13:33
Du hast dir die Frage doch schon selbst beantwortet: Nein.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.121 Beiträge
 
Delphi 11 Alexandria
 
#3

AW: Löschen von files , by Name Pattern

  Alt 16. Sep 2016, 13:35
gibt es eine einfache Lösung / existierende Lösung ?
  Mit Zitat antworten Zitat
Benutzerbild von Dalai
Dalai

Registriert seit: 9. Apr 2006
1.680 Beiträge
 
Delphi 5 Professional
 
#4

AW: Löschen von files , by Name Pattern

  Alt 16. Sep 2016, 13:41
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
  Mit Zitat antworten Zitat
bernhard_LA

Registriert seit: 8. Jun 2009
Ort: Bayern
1.121 Beiträge
 
Delphi 11 Alexandria
 
#5

AW: Löschen von files , by Name Pattern

  Alt 16. Sep 2016, 13:59
Problem gelöst, war ein Fehler in meinem Pattern ...
  Mit Zitat antworten Zitat
nahpets
(Gast)

n/a Beiträge
 
#6

AW: Löschen von files , by Name Pattern

  Alt 16. Sep 2016, 14:24
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;
  Mit Zitat antworten Zitat
Antwort Antwort


Forumregeln

Es ist dir nicht erlaubt, neue Themen zu verfassen.
Es ist dir nicht erlaubt, auf Beiträge zu antworten.
Es ist dir nicht erlaubt, Anhänge hochzuladen.
Es ist dir nicht erlaubt, deine Beiträge zu bearbeiten.

BB-Code ist an.
Smileys sind an.
[IMG] Code ist an.
HTML-Code ist aus.
Trackbacks are an
Pingbacks are an
Refbacks are aus

Gehe zu:

Impressum · AGB · Datenschutz · Nach oben
Alle Zeitangaben in WEZ +1. Es ist jetzt 18:05 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