【发布时间】:2017-09-01 23:09:59
【问题描述】:
我有一个正在读取 excel 电子表格的脚本。每个文件在打开之前都会被复制到一个新位置,以确保文件中同时没有其他人。奇怪的是,有时我的脚本会因为在新位置找不到文件而中断。
# copy the file to a new destination
# the file is originating on a windows file server,
# the destination is my local downloads folder on a windows machine.
FileUtils.cp(some_filepath, destination_path)
# the next line gives an error, because the file doesnt exist at its location yet
Spreadsheet.open(file_at_new_destination)
我已尝试执行until 块,在脚本继续执行之前检查文件是否存在,但即使这样也不起作用,只会永远运行。
# check if file exists
until File.exist?(file_at_new_destination) do
print '.'
end
如何确保脚本在文件完成移动之前不会继续运行?
这是我的 rake 任务中出现的错误
rake aborted!
Errno::ENOENT: No such file or directory @ rb_sysopen -
C:\Users\ALilland\Downloads\tmp_dest\102035 Western Digital Job Status Reports.xls
【问题讨论】:
-
我认为命名约定是这里的问题所在。你可以检查控制台 File.exist 吗?(路径)?看看我们是否需要转义一些特殊字符,如空格或:或反斜杠。