【问题标题】:How to use FileUtils cp using directory name with spaces in Windows?如何在 Windows 中使用带空格的目录名使用 FileUtils cp?
【发布时间】:2012-09-10 16:58:20
【问题描述】:

我尝试使用此线程中的建议无济于事:How to use copyfile when there are spaces in the directory name?。需要明确的是,我正在使用的目录已经在双引号中,并且我尝试转义空格,但仍然得到相同的错误。这是我收到的错误消息:

    Error: Failed to open PDF file:
    C:/Documents
    Error: Failed to open PDF file:
    and
    Error: Failed to open PDF file:
    Settings/cpengelly/My
    Error: Failed to open PDF file:
    Documents/Dropbox/theproject/tmp/working/main
    Error: Failed to open PDF file:
    pdf.pdf
    Errors encountered.  No output created.
    Done.  Input errors, so no output created.

这是怎么回事?

【问题讨论】:

  • 可能是一些来源或其他东西。你试过逃离这个空间吗?
  • 是的,试过了,还是一样的错误。

标签: ruby windows directory cp fileutils


【解决方案1】:

您只需将目录名称放在双引号中。示例 -

FileUtils.cp("C:\\Program Files\\FileZilla\\dbghelp.dll","c:\\temp")

【讨论】:

  • 我应该澄清一下目录名已经用双引号括起来了,对不起!
  • 在您的示例中,绝对文件名没有双引号。而不是pdf_path = "#{working_path}\/#{pdf_name}",你应该使用pdf_path = "\"#{working_path}/#{pdf_name}\""
  • 嗯,试过了,现在除了之前的错误之外还得到了这个:pastebin.com/tKdjbX6X 我认为此时我的代码中的其他地方一定有问题。
猜你喜欢
  • 2011-12-12
  • 2022-01-17
  • 1970-01-01
  • 2012-03-19
  • 2020-05-30
  • 2021-07-17
  • 1970-01-01
  • 2018-11-07
相关资源
最近更新 更多