<?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 - Is a directory empty? - Delphi, Lazarus, Free Pascal				            </title>
            <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-is-a-directory-empty/</link>
            <description>Tweaking4All.com Discussion Board</description>
            <language>en-US</language>
            <lastBuildDate>Thu, 12 Mar 2026 20:06:29 +0000</lastBuildDate>
            <generator>wpForo</generator>
            <ttl>60</ttl>
							                    <item>
                        <title>RE: Lazarus Pascal - Is a directory empty?</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-is-a-directory-empty/#post-5984</link>
                        <pubDate>Wed, 13 Aug 2025 10:01:57 +0000</pubDate>
                        <description><![CDATA[The previous function checks if a directory is completely empty, meaning: it has files and/or directories in it.
Sometimes you don&#039;t care if there are any empty subdirectories, so the follo...]]></description>
                        <content:encoded><![CDATA[<p>The previous function checks if a directory is completely empty, meaning: it has files and/or directories in it.</p>
<p>Sometimes you don't care if there are any empty subdirectories, so the following variant tests if there are any files in the directory or its subdirectories. So it will only look for <strong>files</strong>! Empty directories are ignored, and subdirectories are recursed through to find at least one file.</p>
<p>I made it generic, so we can toggle this on and off.</p>
<p>Set <strong>checkForFilesOnly</strong> to <strong>true</strong> to only look for files. <br />Set it to <strong>false</strong> to look for any files or directories (like the previous version).</p>
<pre contenteditable="false">function isEmptyDirectory(aDir:string; checkForFilesOnlys:boolean = false):boolean;
var
  SearchRecResult: TSearchRec;
  FoundAFile: boolean;
begin
  FoundAFile := FindFirst(IncludeTrailingPathDelimiter(aDir) + '*', faAnyFile, SearchRecResult) = 0;

  while FoundAFile and
        ( DirectoryExists(IncludeTrailingPathDelimiter(aDir)+SearchRecResult.Name) and
          ( (SearchRecResult.Name='.') or
            (SearchRecResult.Name='..') or
            (checkForFilesOnlys and isEmptyDirectory(IncludeTrailingPathDelimiter(aDir)+SearchRecResult.Name)) ) ) do
      FoundAFile := FindNext(SearchRecResult) = 0;

  FindClose(SearchRecResult);
  Result := not(FoundAFile);
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-is-a-directory-empty/#post-5984</guid>
                    </item>
				                    <item>
                        <title>Lazarus Pascal - Is a directory empty?</title>
                        <link>https://www.tweaking4all.com/forum/delphi-lazarus-free-pascal/lazarus-pascal-is-a-directory-empty/#post-2057</link>
                        <pubDate>Wed, 18 Mar 2020 13:19:42 +0000</pubDate>
                        <description><![CDATA[For one of my projects, I needed to determine if a directory was empty, and I couldn&#039;t find a function for this.So I wrote a tiny procedure that does this for us, and it should cover Windows...]]></description>
                        <content:encoded><![CDATA[<p>For one of my projects, I needed to determine if a directory was empty, and I couldn't find a function for this.<br />So I wrote a tiny procedure that does this for us, and it should cover Windows, Linux and MacOS:</p>
<pre>function isEmptyDirectory(aDir:string):boolean;<br />var<br />  SearchRecResult: TSearchRec;<br />begin<br />  Result := FindFirst(IncludeTrailingPathDelimiter(aDir) + '*', faAnyFile, SearchRecResult)&lt;&gt;0;<br /><br />  while (SearchRecResult.Name = '.') or (SearchRecResult.Name = '..') do<br />    Result := FindNext(SearchRecResult) &lt;&gt; 0;;<br /><br />  FindClose(SearchRecResult);<br />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-is-a-directory-empty/#post-2057</guid>
                    </item>
							        </channel>
        </rss>
		