我试图在 ruby 中复制一个文件夹,但收到“无法将目录复制到自身”的错误
我不明白为什么会发生这种情况,有人可以解释一下吗?以及如何实现它以复制具有新名称的完整文件夹。这是我的代码,我尝试在其中复制名称中带有时间戳的源文件夹。
$releaseFolder = 'D:\ruby_workspace\fpsupdater\release'
$frontendSubPath = '\server\pdixfrontend\tomcat\conf'
$backendSubPath = '\server\pdixbackend\tomcat\conf\Catalina'
def println(text)
puts $timestamp.inspect + ': ' + text
end
def getFileTimestamp()
stamp = $timestamp.inspect
stamp.gsub!(/\s+|:|\++/,"_")
end
def backupContext()
target = @configHash["target"]
if (Dir.exists?(target))
println("backup of target " + target)
println("need to backup: " + target + $frontendSubPath)
println("need to backup: " + target + $backendSubPath)
source = "#{target}#{$frontendSubPath}"
backup = "#{target}#{$frontendSubPath}\\" + getFileTimestamp + "_conf"
println(source)
println(backup)
FileUtils.cp_r source , backup
else
puts "cannot backup because target does not exists"
end
end