What is the reason for this behaviour of Find.find?
When I have a script at
D:\Downloads\Ruby 2.5.3\rbL\comp\codeShort.rb with few other files in the same folder, the following searches only the folder where the
.rb script is located:
When I have a script at
D:\Downloads\Ruby 2.5.3\rbL\codeShort.rb with many other files in the same folder, the same code as above searches the entire disk D.
To search the entire disk D in the first case, I did this:
But I don't understand why the two cases behave differently with the same instruction just because they script are in different directories.
Updated by shevegen (Robert A. Heiler) about 1 month ago
I can not say whether this is the case or not (I work only on Linux), also due to me
using Dir preferentially instead. With Dir I always make sure to have a trailing
'/' token if I wish to work with directories, and subdirectories, respectively, e.g:
Based on that I tend to then use .select or .reject, such as when I wish to find
only certain files. There is also Dir.glob() but I sort of transitioned into Dir
completely - it just seems so much simpler to me than all alternatives.
Back to your comment - it may be best to compare the results that you have found
with Find.find(), to Dir, and look whether there are any alternatives that may
be a bug. If it is a bug, it could help the ruby core team if you could reproduce
it into a small use case that they can test (I think most ruby core team members
use linux or mac, although perhaps some also have windows or some dual-boot setup.)
The easier it can be made for the core team to test, the better if the goal is to
resolve problems (if they are really problems that is).
On a side note - I have found that my ruby code works fine on windows too even if
I just use "/" in file paths. The reason I adopted trailing / a long time ago is
because it made it simpler to me, understanding what is going on. Perhaps your
description may also be an example where trailing / are bettr to use, as in them
being more explicit - even if there should not be a difference (I really can't
say, I don't use or seem to need Find.find() really).
Updated by Dan0042 (Daniel DeLorme) about 1 month ago
From what I remember of Windows,
Find.find('D:') would search in the current directory of D:
My guess is that you're actually executing the first script from
D:\Downloads\Ruby 2.5.3\rbL\comp\ and the second script from
D:\ (or maybe
So you may want to check the value of
Dir.pwd in each case.