Showing posts with label Delete. Show all posts
Showing posts with label Delete. Show all posts

Monday, 31 October 2016

Solution to Delphi IDE Freezing Problem

Over the last few years I've been using Delphi XE, and on quite a few occasions the IDE can just freeze for what seems to be no reason. It does not appear to be an issue with small projects, but mainly larger projects and might relate to code insight and how I have it configured. When this problem occurred I use to 'End Task' in task manager, which meant potentially losing some work, but the best solution for when this happens to to find the directory that contains all the 'dcu' files and delete them.

Monday, 1 July 2013

Delete files with a wildcard

Here is how to delete files with a wildcard. It requires SysUtls in the uses clause.

procedure DeleteFiles(FilePath, Wildcard: string);
var cSearchRec: TSearchRec;
    iFind     : integer;
    sPath     : string;
begin
    sPath := IncludeTrailingPathDelimiter(FilePath);
    iFind := FindFirst(sPath + Wildcard, faAnyFile, cSearchRec);
    while iFind = 0 do
    begin
        DeleteFile(sPath + cSearchRec.Name);
        iFind := FindNext(cSearchRec);
    end;
    FindClose(cSearchRec);

end;

In the while loop you can add additional conditions, like only files that have a specific prefix e.g.

if Pos(fPrefix, Copy(cSearchRec.Name, 0, Length(fPrefix))) > 0 then