<?xml version="1.0" encoding="UTF-8"?>        <rss version="2.0"
             xmlns:atom="http://www.w3.org/2005/Atom"
             xmlns:dc="http://purl.org/dc/elements/1.1/"
             xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
             xmlns:admin="http://webns.net/mvcb/"
             xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
             xmlns:content="http://purl.org/rss/1.0/modules/content/">
        <channel>
            <title>
									Lazarus Pascal - Detect if directory has certain file types (cross platform, and optional subdirs) - Delphi, Lazarus, Free Pascal				            </title>
            <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-detect-if-directory-has-certain-file-types-cross-platform-and-optional-subdirs/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Wed, 22 Apr 2026 21:08:34 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Lazarus Pascal - Detect if directory has certain file types (cross platform, and optional subdirs)</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-detect-if-directory-has-certain-file-types-cross-platform-and-optional-subdirs/#post-5986</link>
                        <pubDate>Thu, 14 Aug 2025 12:08:27 +0000</pubDate>
                        <description><![CDATA[For those wanting to use this with an OnDropFiles event:
procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
var
  Counter:integer;
  hasSuitableFiles:bool...]]></description>
                        <content:encoded><![CDATA[<p>For those wanting to use this with an OnDropFiles event:</p>
<pre contenteditable="false">procedure TForm1.FormDropFiles(Sender: TObject; const FileNames: array of string);
var
  Counter:integer;
  hasSuitableFiles:boolean;
  // ...
begin
  // check if suitable files are included 
  hasSuitableFiles := false;
  for Counter:=0 to Length(FileNames)-1 do
    if DirectoryExists(Filenames) and DirectoryHasTheseFiles(Filenames,'*.ext1;*.ext2;',true) then
      begin
        hasSuitableFiles := true;
        break;
      end
    else if (pos('*'+ExtractFileExt(Filenames)+';', '*.ext1;*.ext2;')&gt;0) then
      begin
        hasSuitableFiles:=true;
        break;
      end;

  // no suitable files found, exit ...
  if not hasSuitableFiles then exit;   

  // do your thing
end;</pre>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-detect-if-directory-has-certain-file-types-cross-platform-and-optional-subdirs/#post-5986</guid>
                    </item>
				                    <item>
                        <title>Lazarus Pascal - Detect if directory has certain file types (cross platform, and optional subdirs)</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-detect-if-directory-has-certain-file-types-cross-platform-and-optional-subdirs/#post-5985</link>
                        <pubDate>Thu, 14 Aug 2025 12:03:27 +0000</pubDate>
                        <description><![CDATA[For one of my applications I needed a function to determine if a directory, and optionally its sub directories, had at least one file with a certain file extension. So I wrote one myself, ho...]]></description>
                        <content:encoded><![CDATA[<p>For one of my applications I needed a function to determine if a directory, and optionally its sub directories, had at least one file with a certain file extension. So I wrote one myself, hopefully someone can use this.</p>
<pre contenteditable="false">FoundFiles := DirectoryHasTheseFiles(Dirname, '*.ext1,*ext2;', true);</pre>
<p><strong>aDir</strong> is a directory (regular filename would not be checked!).<br /><strong>SearchMask</strong> is your typical mask '*.ext1;*.ext2;*.ext3;'.<br /><strong>CheckSubDirs</strong> is a boolean to set if sub directories should be searched as well.</p>
<p>As soon as a matching file has been found, the search stops and exits with a positive outcome (true).<br />If no matching file was found, the result will be false.</p>
<p><em>Note</em>: Uses sysutils unit.</p>
<pre contenteditable="false">  function DirectoryHasTheseFiles(aDir:string; SearchMask:string; checkSubDirs:boolean):boolean;
  var
    SearchRecResult: TSearchRec;
    FoundAFile: boolean;

    function ValidExtension:Boolean;
    begin
      Result := (pos('*'+ExtractFileExt(SearchRecResult.Name)+';', SearchMask)&gt;0);
    end;

  begin
    SearchMask := SearchMask+';'; // in case the list doesn't end with a ";"
    FoundAFile := FindFirst(IncludeTrailingPathDelimiter(aDir) + '*', faAnyFile, SearchRecResult) = 0;
    Result     := False;

    while FoundAFile and not(Result) do
      begin
        // Found a matching extensions that is not a directory
        if not(DirectoryExists(IncludeTrailingPathDelimiter(aDir)+SearchRecResult.Name)) and ValidExtension then
          begin
            Result := true;
            break;
          end;

        // if checkSubDirs search subdirs are not . or ..
        if checkSubDirs and
           ( SearchRecResult.Name&lt;&gt;'.') and
           ( SearchRecResult.Name&lt;&gt;'..') and
           DirectoryExists(IncludeTrailingPathDelimiter(aDir)+SearchRecResult.Name) then
          begin
            if DirectoryHasTheseFiles(IncludeTrailingPathDelimiter(aDir)+SearchRecResult.Name, SearchMask, checkSubDirs) then
              begin
                Result := true;
                break;
              end;
          end;

        FoundAFile := FindNext(SearchRecResult)=0;
      end;

    FindClose(SearchRecResult);
  end;         </pre>
<p> </p>]]></content:encoded>
						                            <category domain="https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/">Delphi, Lazarus, Free Pascal</category>                        <dc:creator>Hans</dc:creator>
                        <guid isPermaLink="true">https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-detect-if-directory-has-certain-file-types-cross-platform-and-optional-subdirs/#post-5985</guid>
                    </item>
							        </channel>
        </rss>
		