为什么这个 glob 不能用于我的服务器的 Rake FileList?

发布于 2024-12-26 02:00:54 字数 629 浏览 3 评论 0原文

我为什么从以下位置得到一个空文件列表:

  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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

三生殊途 2025-01-02 02:00:54

Ruby 的 File.join 旨在成为您处理文件路径时的帮手,通过以独立于系统的方式构建它们:

File.join('a','b','c')
=> "a/b/c" 

因此:

DEPLOYMENT_PATH = File.join('', 'myserver', 'andsomepath')
=> "/myserver/andsomepath"

Ruby 通过感知操作系统来确定文件路径分隔符,并且假设自动提供正确的值。在 Windows XP、Linux 和 Mac OS 上:

File::SEPARATOR
=> "/"

File.join(DEPLOYMENT_PATH, '**', '*')
=> "/myserver/andsomepath/**/*"

虽然您可以忽略该帮助程序,但它可以让您的生活更轻松。因为您正在针对服务器工作,所以您可能需要查看 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:

File.join('a','b','c')
=> "a/b/c" 

So:

DEPLOYMENT_PATH = File.join('', 'myserver', 'andsomepath')
=> "/myserver/andsomepath"

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:

File::SEPARATOR
=> "/"

File.join(DEPLOYMENT_PATH, '**', '*')
=> "/myserver/andsomepath/**/*"

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 to SEPARATOR and ignore the warning, letting Ruby do the rest.

风吹雨成花 2025-01-02 02:00:54

如果您

Dir.glob("#{DEPLOYMENT_PATH}\**\*")

编辑:会发生什么?我认为 Ruby 更喜欢您执行 Unix 风格的斜杠,即使您在 Windows 上也是如此。我认为其基本原理是,相同的代码在 Unix 和 Windows 上运行会更好,即使它在 Windows 上看起来很奇怪。

tl;dr:如果它适用于 / 但不适用于 \,则使用有效的方法。

What happens if you do

Dir.glob("#{DEPLOYMENT_PATH}\**\*")

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.

握住我的手 2025-01-02 02:00:54

因为:

 > "\*" == "*"
 => true 

使用 "\\**\\*" 代替。

Because:

 > "\*" == "*"
 => true 

Use "\\**\\*" instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文