Module: Utilities::Files
- Defined in:
- lib/utilities/files.rb
Class Method Summary collapse
- .lines_per_file(files) ⇒ Object
- .recognized_batch_file_type?(file) ⇒ Array [Boolean, String]
- .replace(original_file, new_file) ⇒ Boolean
Class Method Details
.lines_per_file(files) ⇒ Object
4 5 6 7 8 9 |
# File 'lib/utilities/files.rb', line 4 def self.lines_per_file(files) puts 'Lines per file: ' files.each do |f| puts `wc -l #{f}` end end |
.recognized_batch_file_type?(file) ⇒ Array [Boolean, String]
13 14 15 16 17 18 19 20 21 |
# File 'lib/utilities/files.rb', line 13 def self.recognized_batch_file_type?(file) mimetype = `file -b "#{file.path}"`.gsub(/\n/, '') case mimetype when /utf-8/i, /ascii/i, /bibtex/i return [true, mimetype] else return [false, mimetype] end end |
.replace(original_file, new_file) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/utilities/files.rb', line 27 def self.replace(original_file, new_file) return false unless File.exist?(original_file) && File.exist?(new_file) fo = original_file ft = fo + '.tmp' begin File.rename(fo, ft) File.rename(new_file, fo) File.delete(ft) if File.exist?(ft) rescue return false ensure unless File.exist?(original_file) # as we exit we must have a file there File.rename(ft, original_file) end end true end |