Skip to content

Instantly share code, notes, and snippets.

@lqqyt2423
Created February 25, 2019 04:36
Show Gist options
  • Save lqqyt2423/f1eae0ca18e1c61522d9fdbe91f80138 to your computer and use it in GitHub Desktop.
Save lqqyt2423/f1eae0ca18e1c61522d9fdbe91f80138 to your computer and use it in GitHub Desktop.
require "fileutils"
# 循环文件夹的块包装
def each_dir(dirname)
Dir.open(dirname) do |dir|
dir.each do |name|
next if name == "."
next if name == ".."
yield name
end
end
end
# 当前执行目录
pwd = Dir.pwd
each_dir(pwd) do |filename|
pathname = File.join(pwd, filename)
if File.directory?(pathname)
puts pathname
each_dir(pathname) do |subFilename|
if /\.mkv$/ =~ subFilename
print "\t", subFilename, "\n"
tmp_name = File.join(pathname, subFilename)
# mv
FileUtils.mv tmp_name, pwd
end
end
# rm -r
FileUtils.rm_r pathname
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment