In Ruby, how would I find all .csv files in a folder and print out path to the files that contain the word "meh"?


This method is significantly more direct and efficient:

d ='.') do |e| 
  /^.+.csv$/.match(e) && IO.readlines(e).grep(/meh/).length > 0

This should do it assuming you want to search the current directory

d ='.')

# This will find all files whose path ends in .csv
csvs = {|e| /^.+.csv$/.match(e)}

# This will find all .csv files that contain one or more instance 
# of the pattern /meh/
mehs = do |e| 
  f =
  [*f.each_line].grep(/meh/).length > 0

You can't print Word files directly from browser unless user has a word processor extension for browser like Zotero. An other option is to convert your doc file to PDF, HTML or image format. wvWare is a software you can do this with. see:

To create word files with PHPWord. see:

With this you can save your doc(x) files and add the links to your php page. Or you can directly download file when opening a PHP page by creating custom headers:

header('Content-Type: application/');
header('Content-Disposition: attachment;filename="myfile.docx"');
header('Cache-Control: max-age=0');

// Code that generates DOC

// output the file to the browser
$objWriter = PHPWord_IOFactory::createWriter($PHPWord, 'Word2007');

See forum thread here:

Use an if-else statment to check if w.length() == 5 or not.

Although you don't mention what problem you're trying to solve, since your code runs I'm going to assume the issue is that the output file is empty.

The reason for that is that you're not flushing or closing the file before your program exits. Just add a new_file.close() at the very end and that should get you going.

If you ever used cygwin, it includes xmllint which in turn has the --format option. This was my original approach. However xmllint did not format attributes the way I liked, so I have developed my own script. Since the word documents contain a lot of rsid noise, the script has an option to remove it.

I use the following worklflow:

  • get a word document, let say foo.docx
  • explode-docx -r foo.docx
  • edit foo.docx - make a small change
  • explode-docx -r foo.docx
  • kdiff3 foo foo.bak

Message :
Login to Add Your Comments .
Privacy Policy - Copyrights Notice - Feedback - Report Violation - RSS 2017 © All Rights Reserved .