Project

General

Profile

Misc #16396

What is the reason for this behaviour of Find.find?

Added by stiuna (Juan Gregorio) 8 months ago. Updated 7 months ago.

Status:
Open
Priority:
Normal
Assignee:
-
[ruby-core:96079]

Description

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:

Find.find('D:')

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:

Find.find('D:/')

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) 7 months 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:

pp Dir['/tmp/**/**/']

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 stiuna (Juan Gregorio) 7 months ago

pp Dir['/tmp/**/**/']

Hello, I loved your alternative, from now on I'll use Dir.

Regarding the "bug" of Find I think I can prove it one of these days I report it.

#3

Updated by sawa (Tsuyoshi Sawada) 7 months ago

  • Description updated (diff)
#4

Updated by sawa (Tsuyoshi Sawada) 7 months ago

  • Description updated (diff)

Updated by Dan0042 (Daniel DeLorme) 7 months 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 C:\some\dir\?)
So you may want to check the value of Dir.pwd in each case.

Also available in: Atom PDF