Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8857999
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T14:43:33+00:00 2026-06-14T14:43:33+00:00

I am currently developing a script that look for files in a specific folder.

  • 0

I am currently developing a script that look for files in a specific folder.
I want to duplicate those files. Then I want to remove some useless lines from those duplicate files, parse them in YAML (this is the format of content in it). And finally make a diff of the files.

I was firstly thinking to copy them in a tmp folder but I just discovered the existence of Tempfile which seems to be exactly what I need since the temporary files have to be deleted after the script has done its job.

What I have for now:

require 'Tempfile'
require 'YAML'

PWD = File.dirname(__FILE__)
LOCALES_FOLDER_PATH = "#{PWD}/../app/assets/javascripts/ayl/bo/config/locales"
LOCALES = ['en', 'fr']

files_data = {}
locale_file_names = LOCALES.map{|locale| "#{locale}.js.coffee"}
files = locale_file_names.map do |locale_file_name|
  files_data[locale_file_name] = "#{LOCALES_FOLDER_PATH}/#{locale_file_name}"
end

locale_files = []
files.each do |file|

  content = File.open(file).read
  locale_file = Tempfile.open file.gsub("/", "_") do |f|
    f.write content
    f.flush
    puts f.read
  end
  locale_files << locale_file

end

Results in:

± ruby diff_locales.rb
/Users/adrien/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/YAML.rb:48: warning: already initialized constant ENGINE
/Users/adrien/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/YAML.rb:69: warning: already initialized constant ENGINE
/Users/adrien/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/YAML.rb:73: warning: already initialized constant ENGINE


±

The content of my temporary files is empty.

This seems weird to me. But I assume their is something I just do not know/understand.


OK! Figured it out! Inside the block, I had to move the cursor back to the beginning of the file before reading the content.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T14:43:34+00:00Added an answer on June 14, 2026 at 2:43 pm

    Inside the block, I had to move the cursor back to the beginning of the file before reading the content.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm currently developing a script that takes a Word document, opens it up in
I am currently developing a script that requires images stored into Mongo with GridFS,
I'm currently developing a script that takes a message, splits it apart every 100
I'm currently developing a script for a map in COD4. I think that the
I'm currently developing a website in HTML and I want to copy some of
I'm currently developing what is more or less a script that needs to get
I'm currently developing a Safari extension that uses an injected script to further inject
I am currently developing a responsive website. I've developed a jquery script that changes
I am currently developing a very simple script in AutoHotKey, but it involves using
I am currently developing an application , that will be published on appstore. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.