0
我有一个阅读excel电子表格的脚本。每个文件在被打开之前被复制到一个新的位置,确保文件中没有其他人同时处于该位置。奇怪的是,有时我的脚本因为文件不能在新的位置找到而中断。Ruby - 如何等待文件在下一个动作之前完成移动?
# 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 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?(路径)?看看我们是否需要逃离一些特殊的字符,如空间或:或反斜杠。 – Mohanraj