Read any extension .txt file inside a specific folder in ruby every 2 minutes

0

I want to read every 2 minutes all the files one by one from an example folder C: \ folder \ all those that have a txt extension. but I do not know the names of each file because they are random. after reading it would be convenient to eliminate them to avoid overload ..

Will someone have an idea of how it could be done?

    
asked by Jonathan Zambrano 30.11.2017 в 14:27
source

1 answer

0

Use Dir # [] to get the file array and do whatever you want with them:

Dir['C:\folder\*.txt'].each do |file|
  # Lo que quieras hacer
  # por ejemplo SecretObject.new(File.read(file)).save
  File.rm(file)
end

For that process to be repeated every two minutes you can use sleep and loop :

loop do
  # procesar_archivos()
  sleep 120
end
    
answered by 22.01.2018 / 20:18
source