なぜ、下のクラスはディレクトリ "print" \ n "+ f"のディレクトリ名とファイル名を出力しますか? ファイルを出力したいだけですが、ディレクトリも出力されています。Rubyクラスがファイルとディレクトリを出力しています
class Sort
require 'find'
directoryToSort = "c:\\test"
total_size = 0
Find.find(directoryToSort) do |path|
if FileTest.directory?(path)
if File.basename(path)[0] == ?.
Find.prune # Don't look any further into this directory.
else
Dir.foreach(path) do
|f|
# do whatever you want with f, which is a filename within the
# given directory (not fully-qualified)
if !FileTest.directory? f
print "\n"+f
end
end
next
end
else
end
end
end
+1 Slartibartfast!その素晴らしいフィヨルドに感謝します! – Tilo