Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用ruby或shell脚本在另一个文件夹中移动文件夹?_Ruby_Shell - Fatal编程技术网

使用ruby或shell脚本在另一个文件夹中移动文件夹?

使用ruby或shell脚本在另一个文件夹中移动文件夹?,ruby,shell,Ruby,Shell,我有一个公用文件夹名Vijay,其中有许多文件夹 文件夹名称,例如: 32,032,055,056,095 如何将名为32的文件夹移动到032文件夹中 我需要Ruby脚本或shell脚本 提前感谢。使用系统命令: `mv 32 032/` 或者: FileUtils.mv '32', '032/' , :force => true 您可能希望使用它们的完整路径。您可以执行以下操作: require 'fileutils' FileUtils.cp_r("path_to_vijay/32

我有一个公用文件夹名
Vijay
,其中有许多文件夹

文件夹名称,例如:

32
032
055
056
095

如何将名为
32
的文件夹移动到
032
文件夹中

我需要Ruby脚本或shell脚本

提前感谢。

使用系统命令:

`mv 32 032/`
或者:

FileUtils.mv '32', '032/' , :force => true
您可能希望使用它们的完整路径。

您可以执行以下操作:

require 'fileutils'
FileUtils.cp_r("path_to_vijay/32/","path_to_vijay/032/")
阅读文档

将src复制到dest。如果src是一个目录,那么这个方法递归地复制它的所有内容如果dest是目录,则将src复制到dest/src。

例如:-

require 'fileutils'

# see here the test2 directoy is empty
Dir.glob("#{__dir__}/test2/**/*") # => []
# look at the content of the test1 directory, which will be copied by it
# parent directory to test2
Dir.glob("#{__dir__}/test1/**/*") # => ["/home/arup/Ruby/test1/a.rb"]

FileUtils.cp_r("#{__dir__}/test1/","#{__dir__}/test2/")

# see the test1 directory itself got copied with all its contents to the
# test2/ directory
Dir.glob("#{__dir__}/test2/**/*")  
# => ["/home/arup/Ruby/test2/test1", "/home/arup/Ruby/test2/test1/a.rb"]

我不明白,你只想把“032”文件夹移到“32”文件夹而不想别的?为什么不在shell中简单地使用
mv
,或者在Ruby中使用
FileUtils.move()
?到目前为止,您尝试过任何方法。