https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112019-10-12T10:59:38ZRuby Issue Tracking SystemRuby master - Feature #16249: Dir#empty? and File#empty?https://redmine.ruby-lang.org/issues/16249?journal_id=819902019-10-12T10:59:38Znobu (Nobuyoshi Nakada)nobu@ruby-lang.org
<ul></ul><pre><code class="c syntaxhl" data-language="c"> <span class="k">return</span> <span class="nf">rb_dir_s_empty_p</span><span class="p">(</span><span class="n">rb_cDir</span><span class="p">,</span> <span class="n">rb_str_dup</span><span class="p">(</span><span class="n">dirp</span><span class="o">-></span><span class="n">path</span><span class="p">));</span>
</code></pre>
<p>This checks a directory named the current <code>Dir</code> object opened, instead of the opened directory itself.</p> Ruby master - Feature #16249: Dir#empty? and File#empty?https://redmine.ruby-lang.org/issues/16249?journal_id=819912019-10-12T11:39:44Zshevegen (Robert A. Heiler)shevegen@gmail.com
<ul></ul><p>Personally I think I have wanted/needed this in the past. It has not been<br>
that important to me to suggest it myself, though, but +1 on the name/API.</p>
<blockquote>
<p>(as nobody complained about it, or I can't find similar proposals), but<br>
seems logical to me:</p>
</blockquote>
<p>I think not every thought process alone makes it into a suggestion. :)</p>
<p>A good example is require 'pp'; I was thinking that it would be convenient<br>
before it was suggested to change it, but I never made a proposal myself.<br>
Inertia sometimes wins ... but rubyists may often "think alike", or<br>
in a somewhat similar way, to some extent.</p>
<p>I guess it (whether the API has not existed before) may have to do with what<br>
is/should be possible through FileUtils. So perhaps the opinion is or was<br>
that the file-related activities, directory-related activities etc... should<br>
all go through FileUtils instead.</p>
<p>We already do have a few file-related activities outside of FileUtils,<br>
though, such as File.delete(). I use the latter a lot, more often than<br>
tapping into FileUtils or the .rm_rf variant (if the task is to delete<br>
the file that is); oddly enough, one minor reason is so that I can avoid<br>
having to do require 'fileutils', a bit similar as to how I like how<br>
require 'pp' became optional - but anyway, I digress, so +1 to the<br>
suggestion in itself.</p>
<p>(I have no particular opinion on the implementation either way; my comment<br>
here is really meant to the Dir.empty?() and File.empty?() API/suggestion<br>
alone.)</p> Ruby master - Feature #16249: Dir#empty? and File#empty?https://redmine.ruby-lang.org/issues/16249?journal_id=821832019-10-19T12:49:58Zzverok (Victor Shepelev)zverok.offline@gmail.com
<ul></ul><p><a class="user active user-mention" href="https://redmine.ruby-lang.org/users/4">@nobu (Nobuyoshi Nakada)</a></p>
<blockquote>
<p>This checks a directory named the current <code>Dir</code> object opened, instead of the opened directory itself.</p>
</blockquote>
<p>I am not sure I understand (probably it is my lack of in-depth filesystem work understanding), for what I can tell, we have a directory object with some path, and check if directory with this path is empty?..</p>