手机版
你好,游客 登录 注册
背景:
阅读新闻

修改目录文件名-Ruby实现

[日期:2012-01-25] 来源:Linx社区  作者:eric [字体:大 中 小]
修改目录文件名-Ruby实现
  1. require 'pathname'  
  2. def change_name  
  3.   puts "------------"  
  4.   current_path = Pathname.new(File.dirname(__FILE__)).realpath  
  5.   current_file_name = __FILE__  
  6.   begin  
  7.     Dir::foreach(current_path) do |file|  
  8.       if file!="." and file!=".." and file!=".#{ current_file_name }.swp" and file!="#{ current_file_name }"  
  9.         #puts "File:"+file    
  10.         1.upto(9) do |i|  
  11.           File.rename("#{ i.to_s }#{ i.to_s }.rb", "#{ i.to_s }.rb")  
  12.           puts "执行第#{ i }个文件"  
  13.         end  
  14.         break  
  15.       end  
  16.     end  
  17.     rescue => e  
  18.       puts "错误:"+e  
  19.     #ensure   
  20.     #  puts "请确保文件名是否匹配!"   
  21.   end  
  22.   puts "------------"  
  23. end  
  24.   
  25.   
  26. change_name  
linux
相关资讯       Ruby 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款