I have a list of .eml files which are in a remote folder say
\\abcremote\pickup
I want to rename all the files from
xyz.eml to xyz.html
Could you guys help me do that using ruby.
Thanks in advance.
You can make RubyMine the default application for opening specific file types from the default file manager on your operating system. Press Ctrl+Alt+S to open the IDE settings and select Editor | File Types. Click Associate File Types with RubyMine and select the file extensions you want to open with the IDE.
You can also do it by right-clicking on the unopened file and clicking on the “Rename” option. Simply change the extension to whatever file format you want and your computer will do the conversion work for you.
An RB file is a software program written in Ruby, an object-oriented scripting language. Ruby is designed to be simple, efficient, and easy to read. RB files can be edited with a text editor and run using Ruby.
Improving the previous answer a little:
require 'fileutils'
Dir.glob('/path_to_file_directory/*.eml').each do |f|
FileUtils.mv f, "#{File.dirname(f)}/#{File.basename(f,'.*')}.html"
end
The File.basename(f,'.*')
will give you the name without the extension otherwise the files will endup being file_name.eml.html instead of file_name.html
Rake offers a simple command to change the extension:
require 'rake'
p 'xyz.eml'.ext('html') # -> xyz.html
Improving the previous answers again a little:
require 'rake'
require 'fileutils'
Dir.glob('/path_to_file_directory/*.eml').each do |filename|
FileUtils.mv( filename, filename.ext("html"))
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With