将文件夹内容复制到 Rake 中的父目录(Windows)

Copy Folder Contents to Parent Directory in Rake (on Windows)

我在文件夹中有一组文件../SomeFolder/AndAnother/dist

dist 文件夹包含一堆我想在 Rake 任务中提升一个级别的文件和文件夹。

所以

../SomeFolder/AndAnother/dist/subFolder/a.txt 变为 ../SomeFolder/AndAnother/subFolder/a.txt

我可以通过

在 linux 上完成此操作
task :lift_to_parent do
  sh('mv', '../SomeFolder/AndAnother/dist/*', '../SomeFolder/AndAnother')
end

但是这个 Rake 任务也在 Windows 上运行,在那个 OS 上我得到 Errno::EACCES: Permission denied @ unlink_internal

我希望 FileUtils.mv 对 linux 和 windows 都有效...

但如果我

task :lift_to_parent do
  FileUtils.mv '../SomeFolder/AndAnother/dist', '../SomeFolder/AndAnother', :force => true
end

我得到 ArgumentError: same file: ../SomeFolder/AndAnother/dist and ../SomeFolder/AndAnother/dist 所以我显然遗漏了一些允许 FileUtils.mv 复制关卡的东西(或者以错误的方式进行)

那么,如何修复我的 FileUtils 版本或以其他方式使用 Rake 任务将文件夹结构复制到其父文件夹?

我已经完成了这个

task : lift_to_parent do
  copied_by_jenkins = '../SomeFolder/AndAnother/dist'
  copy_pattern = "#{copied_by_jenkins}/**/*"
  target_directory = '../SomeFolder/AndAnother/Public'

  next unless File.exists? copied_by_jenkins

  FileList[copy_pattern].each do |file|
    file_path = File.dirname(file).sub! copied_by_jenkins, ''
    file_name = File.basename(file)
    target_directory = File.join(target_directory, file_path)
    destination = File.join(target_directory, file_name)

    FileUtils.mkdir_p target_directory
    FileUtils.copy_file(file, destination) unless File.directory? file
  end

  FileUtils.remove copied_by_jenkins
end

但为了实现我的目标,输入的内容似乎很多