Solved

return files

Posted on 2014-12-19
6
110 Views
Last Modified: 2014-12-23
Hi
I wantt to be able to run a script where the output lists directories and paths to certain file extensions.
For example *.rpt .......
the output might look like ...
c:/reports/a.rpt
c:/reports/b.rpt
c:/reports/test/c.rpt
etc
Regards
0
Comment
Question by:PHIL Sawyer
  • 4
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Andrew Doades
ID: 40509528
require 'rubygems'
require 'fileutils'
require 'find'

Dir.chdir("C:\reports")
Dir["*.rpt"].each do |tempfile|
    puts "Found File #{tempfile} in folder #{Dir.pwd}"
end #xml each
0
 
LVL 10

Accepted Solution

by:
Andrew Doades earned 500 total points
ID: 40509533
... OR


Dir.chdir("C:\reports")
  folders = Dir.glob("**/")
  for fldr in folders
    Dir.chdir("#{fldr}") do
      Dir["*.rpt"].each do |tempfile|
      puts "Found File #{tempfile} in folder #{Dir.pwd}"
    end #chdir
  end #xml each
end#folders
0
 

Author Comment

by:PHIL Sawyer
ID: 40514528
Thanks
0
Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:PHIL Sawyer
ID: 40514537
Is there a way I can sort the output alphabetically for the report names
0
 

Author Comment

by:PHIL Sawyer
ID: 40514639
It's ok I've managed to do it.

Regards
0
 

Author Closing Comment

by:PHIL Sawyer
ID: 40514640
Thanks
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: narshlob
If you've ever programmed in Ruby and have come across either a proc or a lambda, you might have been wondering what the difference is between the two and when you would use one over the other. This article will try to explain the difference between…
Recently I spent hours debugging an issue in a Rails project where ActiveRecord was causing MySQL errors trying to create a User object of a class at the top level of a Single Table Inheritance model structure.  It turns out `.create` behaves differ…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question