这个错误的意思是源文件和目标文件是同一个文件,所以不能将它复制到同一个目录下。
你可以通过在执行复制之前检查源文件和目标文件的路径是否相同来解决此问题。例如:
require 'fileutils'
source_file = "C:/DFC_BIM/Data/User/Common/Coordination/data/vvv_4/阿斯达_16/合模_阿斯达.skp"
destination_dir = "C:/DFC_BIM/Data/User/Common/Coordination/data/vvv_4/阿斯达_16"
if File.expand_path(source_file) != File.expand_path(destination_dir + '/' + File.basename(source_file))
FileUtils.cp(source_file, destination_dir)
else
puts "Source file and destination file are the same."
end
在上面的代码中,我们使用File.expand_path方法将源文件和目标文件的路径都转换为绝对路径,然后比较它们是否相同。如果不相同,就执行复制操作,否则就输出一条消息表示源文件和目标文件是同一个文件。