我遇到了此代码(再次)的问题。 我试图让Ruby来检查tree
是否等于$do_not_scan
中的任何项目,我所得到的全部是“cannot convert Array into String
”错误。任何方式来解决这样的事情?无法将数组转换为字符串(Ruby)
我的代码:
#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
我会用一个正则表达式代替。这将帮助我避免文件夹名称区分大小写的比较问题。此外,我会避免递归,它使用更多的资源,在这种情况下不需要它。 – Myst
您还在不更新'$ trees'的情况下调用扫描。您可以通过将'#scan'和'#scan_loop'方法作为参数传递给全局变量'$ trees'来解决方法 – jphager2
备注 - 请停止使用'$ global'变量。他们只是不使用红宝石。正常变量不需要'$' – DGM