为什么这个 glob 不能用于我的服务器的 Rake FileList?
我为什么从以下位置得到一个空文件列表:
files = FileList.new("#{DEPLOYMENT_PATH}\**\*")
Where DEPLOYMENT_PATH is \\myserver\anndsomepath
如何从这样的服务器获取文件列表?这是 Ruby/Rake 的问题吗?
更新:
我尝试过:
files = FileList.new("#{DEPLOYMENT_PATH}\\**\\*")
files = Dir.glob("#{DEPLOYMENT_PATH}\\**\\*")
files = Dir.glob("#{DEPLOYMENT_PATH}\**\*")
它就可以工作:
//myserver/andsomepath
更新再次:如果我将服务器设置为:并获取如下文件,
files = FileList.new("#{DEPLOYMENT_PATH}/**/*")
How come I get an empty filelist from:
files = FileList.new("#{DEPLOYMENT_PATH}\**\*")
Where DEPLOYMENT_PATH is \\myserver\anndsomepath
How to get a filelist from a server like this? Is this an issue of Ruby/Rake?
UPDATE:
I tried:
files = FileList.new("#{DEPLOYMENT_PATH}\\**\\*")
files = Dir.glob("#{DEPLOYMENT_PATH}\\**\\*")
files = Dir.glob("#{DEPLOYMENT_PATH}\**\*")
UPDATE AGAIN: It works if I put server as:
//myserver/andsomepath
and get files like this:
files = FileList.new("#{DEPLOYMENT_PATH}/**/*")
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
Ruby 的
File.join
旨在成为您处理文件路径时的帮手,通过以独立于系统的方式构建它们:因此:
Ruby 通过感知操作系统来确定文件路径分隔符,并且假设自动提供正确的值。在 Windows XP、Linux 和 Mac OS 上:
虽然您可以忽略该帮助程序,但它可以让您的生活更轻松。因为您正在针对服务器工作,所以您可能需要查看
File::ALT_SEPARATOR
,或者只是重新分配给SEPARATOR
并忽略警告,让 Ruby 完成剩下的工作。Ruby'
File.join
is designed to be your helper when dealing with file paths, by building them in a system-independent way:So:
Ruby determines the file path separator by sensing the OS, and is supposed to automatically supply the right value. On Windows XP, Linux and Mac OS it is:
While you can ignore the helper, it is there to make your life easier. Because you are working against a server, you might want to look into
File::ALT_SEPARATOR
, or just reassigning toSEPARATOR
and ignore the warning, letting Ruby do the rest.如果您
编辑:会发生什么?我认为 Ruby 更喜欢您执行 Unix 风格的斜杠,即使您在 Windows 上也是如此。我认为其基本原理是,相同的代码在 Unix 和 Windows 上运行会更好,即使它在 Windows 上看起来很奇怪。
tl;dr:如果它适用于
/
但不适用于\
,则使用有效的方法。What happens if you do
Edit: I think Ruby prefers you doing Unix-style slashes, even when you're on Windows. I assume the rationale is that it's better for the same code to work on both Unix and Windows, even if it looks weird on Windows.
tl;dr: If it works with
/
but not with\
, then use what works.因为:
使用
"\\**\\*"
代替。Because:
Use
"\\**\\*"
instead.