无法将Array转换为String(Ruby)

时间:2022-01-13 21:43:37

I'm having trouble with this code (again). I'm trying to get Ruby to check if tree is equal to any of the items in $do_not_scan and all I'm getting is a "cannot convert Array into String" error. Any way to fix such a thing?

我再次遇到此代码的问题。我试图让Ruby检查树是否等于$ do_not_scan中的任何项目,而我得到的是“无法将数组转换为字符串”错误。有什么方法可以解决这样的问题吗?

My code:

#filesniffer by Touka, ©2015
$filecount = 0
$trees = Dir.entries("C:\\")
$do_not_scan = ["bootmgr", "BOOTNXT", "USER", ".", "Documents and Settings", "PerfLogs", "System Recovery", "System Volume Information", "$RECYCLE.BIN"]
def scan
    $trees.each do |tree|
        unless tree.include?($do_not_scan[0...8])
            puts "scanning #{tree}"
            entries = Dir.entries("c:\\#{tree}")
            entries.each do |filename|
                if filename == "**\*.dll"
                    puts "Found #{filename} in #{tree}"
                end
            end
        end
    end
end
def scan_loop
    $trees.each do |tree|
        scan
        unless tree.include?($do_not_scan[0...8])
            subtrees = Dir.entries("#{tree}")
            subtrees.each do |tree|
                scan
                scan_loop
            end
        end
    end
end
scan_loop
sleep

1 个解决方案

#1


It looks like the following have to change in the scan and scan_loop methods:

看起来以下必须在scan和scan_loop方法中进行更改:

$do_not_scan[0...8].include?(tree) 

In place off:

到位:

tree.include?($do_not_scan[0...8])

#1


It looks like the following have to change in the scan and scan_loop methods:

看起来以下必须在scan和scan_loop方法中进行更改:

$do_not_scan[0...8].include?(tree) 

In place off:

到位:

tree.include?($do_not_scan[0...8])