我需要使用Ruby连接和计算基于Windows的远程服务器中的文件数。
ruby-1.8.7-p352 :001 > Dir.entries("\\server_name\d$\directory_path").count
我也试过这个
ruby-1.8.7-p352 :002 > file_path = "\\server_name\d$\directory_path".gsub("\\", "/")
ruby-1.8.7-p352 :003 > Dir.entries(file_path).count
上述行似乎不足......因为它们返回
No such file or directory - \\server_name\d$\directory_path (Errno::ENOENT)
分别
答案 0 :(得分:0)
你是否试图展示你的道路?
file_path = "\\server_name\d$\directory_path".gsub("\\", "/")
puts file_path #-> /server_named$directory_path
你必须掩饰\
file_path = "\\\\server_name\\d$\\directory_path"
puts file_path #\\server_name\d$\directory_path
或
file_path = "\\\\server_name/d$/directory_path"
puts file_path #\\server_name/d$/directory_path
我认为你必须用\开始这条路。正常的斜杠//将无效(我不确定这一点,如果我错了就试试其他版本)