Why does Ruby seem to access files in a directory randomly?

前端 未结 2 1535
Happy的楠姐
Happy的楠姐 2021-01-12 16:50

Is this by design?

Here\'s the code:

class FileRenamer
    def RenameFiles(folder_path)    
        files = Dir.glob(folder_path + \"/*\")
    end
en         


        
2条回答
  •  南方客
    南方客 (楼主)
    2021-01-12 17:35

    The answer from Scott is out of date. I ran Dir.glob on Mac OS 10.15.6 Catalina, and the files were not returned in alphabetical order. According to the ruby docs, the ordering is determined by the OS.

    https://ruby-doc.org/core-2.5.1/Dir.html

    Note that the pattern is not a regexp, it's closer to a shell glob. See File.fnmatch for the meaning of the flags parameter. Case sensitivity depends on your system (File::FNM_CASEFOLD is ignored), as does the order in which the results are returned.

提交回复
热议问题