ruby 删除文件夹(包括文件夹中的文件夹和文件)

def deleteDirectory(dirPath)
  if File.directory?(dirPath)
    puts "是文件夹";
	Dir.foreach(dirPath) do |subFile|
	  if subFile != '.' and subFile != '..' 
	    deleteDirectory(File.join(dirPath, subFile));
	  end
	end
	Dir.rmdir(dirPath);
  else
	File.delete(dirPath);
  end
end
puts "删除完毕"
deleteDirectory(File.join(Dir.getwd, 'uexBrokenLine'));
posted @ 2014-04-16 18:21  nil  阅读(2145)  评论(0编辑  收藏  举报