ai didi

ruby-on-rails - ruby rails : How do I move all files from one folder to another folder?

转载 作者:数据小太阳 更新时间:2023-10-29 07:25:19 24 4
gpt4 key购买 nike

但我还需要一种重命名它们的方法,以防发生冲突。

喜欢如果存在?然后 file.name = "1-"+file.name或类似的东西

最佳答案

也许这样的事情对你有用:

origin = '/test_dir'
destination = '/another_test_dir'

Dir.glob(File.join(origin, '*')).each do |file|
if File.exists? File.join(destination, File.basename(file))
FileUtils.move file, File.join(destination, "1-#{File.basename(file)}")
else
FileUtils.move file, File.join(destination, File.basename(file))
end
end

关于ruby-on-rails - ruby rails : How do I move all files from one folder to another folder?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3292358/

24 4 0
文章推荐: ruby-on-rails - 外键 (class_id) 未填充在 belongs_to 关联中
文章推荐: ios - 颜色色调 UIButton 图像
文章推荐: ios - 为什么 ProjectName-Prefix.pch 没有在 Xcode 6 中自动创建?
文章推荐: ios - 将图像或视频添加到 iPhone 模拟器
数据小太阳
个人简介

我是一名优秀的程序员,十分优秀!

滴滴打车优惠券免费领取
滴滴打车优惠券
全站热门文章
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com