output file name based on original file name

C

Collin Moore

I have a simple txt parsing script that I'd like to have the output be
named after the original text file.

original = original.txt
output = original_output.txt

I'm just doing a simple file.open, and couldn't find anything.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|

Thanks in advance for any help.
 
M

Mohit Sindhwani

Collin said:
I have a simple txt parsing script that I'd like to have the output be
named after the original text file.

original = original.txt
output = original_output.txt

I'm just doing a simple file.open, and couldn't find anything.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|

Thanks in advance for any help.

This is the simplest...
output_file = "#{input_file}_output.txt"

On the other hand, you can look at the FileUtils to see how to get the
base name or the name without extension, etc... so that you can make it
more productive. I'm just suggesting the simplest.

Cheers,
Mohit.
10/16/2009 | 1:53 AM.
 
B

Bertram Scharpf

Hi,

Am Freitag, 16. Okt 2009, 02:44:38 +0900 schrieb Collin Moore:
I'm just doing a simple file.open, and couldn't find anything.

File.open('output.txt', 'w') do |f2|
File.readlines("original.txt").each do |line|

Do you get the below error message?

irb(main):001:0> File.exists? "nonexistent"
=> false
irb(main):002:0> File.read "nonexistent"
Errno::ENOENT: No such file or directory - nonexistent
from (irb):2:in `read'
from (irb):2
irb(main):003:0>

Bertram
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,188
Latest member
Crypto TaxSoftware

Latest Threads

Top