ruby遍历文件夹下所有文件,输出文件名(migrate报错处理)
2016-02-01 15:35
471 查看
1.例子:
//注释:file_path文件路径
def traverse_dir(file_path)
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file !=”.” and file !=”..”
traverse_dir(file_path+”/”+file)
end
end
else
puts “File:#{File.basename(file_path)}, Size:#{File.size(file_path)}”
//注释:Size可省略
end
end
traverse_dir(‘D:/apache-tomcat’)
//服务器地址:"#{Rails.root}/db/migrate"
2.实际例子
class SchemaMigration < ActiveRecord::Base
def self.traverse_dir(file_path)
# file_path=”#{Rails.root}/db/migrate”
a=[]
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file !=”.” and file !=”..”
traverse_dir(file_path+”/”+file)
end
end
else
a<<”#{File.basename(file_path)}”
end
b=[]
a.each do |x|
b<
//注释:file_path文件路径
def traverse_dir(file_path)
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file !=”.” and file !=”..”
traverse_dir(file_path+”/”+file)
end
end
else
puts “File:#{File.basename(file_path)}, Size:#{File.size(file_path)}”
//注释:Size可省略
end
end
traverse_dir(‘D:/apache-tomcat’)
//服务器地址:"#{Rails.root}/db/migrate"
2.实际例子
class SchemaMigration < ActiveRecord::Base
def self.traverse_dir(file_path)
# file_path=”#{Rails.root}/db/migrate”
a=[]
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file !=”.” and file !=”..”
traverse_dir(file_path+”/”+file)
end
end
else
a<<”#{File.basename(file_path)}”
end
b=[]
a.each do |x|
b<
相关文章推荐
- ruby on rails常用命令mark
- GitLab,是一个使用 Ruby on Rails 开发的开源应用程序,与Github类似,能够浏览源代码,管理缺陷和注释,非常适合在团队内部使用。 官方只提供了Debian/Ubuntu系统下的安
- ruby元编程4------类
- 再谈PHP、Python与Ruby
- RubyGems 镜像 - 淘宝网
- BT5 MetaSpolit如何配置Ruby和Gem
- ruby中sequel使用dateformat等function
- ruby元编程3------代码块
- 整理Ruby相关的各种概念(rvm, gem, bundle, rake, rails等)
- 安装ruby on rail
- ruby元编程2------method
- 【Ruby】Ruby的model学习——Active Record Associations
- 安装rails-for-ruby环境并运行rails项目全过程
- deepin使用rvm安装ruby出现make: *** [build-ext] Error 2错误
- ruby中sequel多进程插入数据主键冲突
- 在没有数据库表或者列的情况下新建model;rails ,ruby, rack
- ruby 基础知识点
- 安装Pod之前的工作——安装ruby环境
- IIS7 上配置运行 Ruby CGI环境
- Ruby的几道题目