You probably did not add the linux-only unit "clocale" to the uses clauses when going from Windows to Linux. This applies the format settings of your system to the DefaultFormatSettings record of your appliation.
Just a remark: After changing the DefaultformatSettings for this short conversion routine you should restore the old DefaultFormatsettings to avoid that the application behaves differently from now on. Or better: Do not touch DefaultFormatSettings at all, but use a local copy which you provide as additional parameter to StrToDate:
procedure VerwijderOudeBackups;
var
fs: TFormatSettings;
begin
fs := DefaultFormatSettings;
fs.DateSeparator := '-';
fs.ShortDateFormat := 'dd-mm-yyyy';
...
fdate := StrToDateTime(fd, fs);
...
end;
I also would not use the ShortDateFormat 'dd-mm-yyyy', but 'dd/mm/yyyy' since the slash '/' is automatically replaced by the value of the DateSeparator which gives you greater flexibility.
Another idea, maybe, is to use the TryStrToDateTime variant which does not raise an exception in case of a format error. In this case you can try other date formats if you find that the structure of your filenames is not consistent:
var
fs: TFormatSettings;
begin
fs := DefaultFormatSettings;
fs.DateSeparator := '-';
fs.ShortDateFormat := 'dd/mm/yyyy';
if not TryStrToDateTime(fd, fs, fdate) then
begin
fs.DateSeparator := '.';
if not TryStrToDatetime(fd, fs, fdate) then
raise Exception.CreateFmt('The filename "%s" contains an invalid date which must be in the format "dd-mm-yyyy" or "dd.mm.yyyy"', [fn]);
Final remark:
The StrToDateTime conversion is often very strict. In many cases, it is easier to use the
ScanDateTime function from unit DateUtil.