From a76a8a080466f7a11b3b712b04507450890944cf Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Sun, 26 Feb 2012 20:55:09 -0500 Subject: [PATCH] ex17 --- .gitignore | 1 + ex17.rb | 22 ++++++++++++++++++++++ test.txt | 3 +++ 3 files changed, 26 insertions(+) create mode 100644 ex17.rb create mode 100644 test.txt diff --git a/.gitignore b/.gitignore index b25c15b..a3f37ab 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ *~ +copied.txt diff --git a/ex17.rb b/ex17.rb new file mode 100644 index 0000000..d6b07d7 --- /dev/null +++ b/ex17.rb @@ -0,0 +1,22 @@ +from_file, to_file = ARGV +script = $0 + +puts "Copying from #{from_file} to #{to_file}" + +# we could do these two on one line too, how? +input = File.open(from_file) +indata = input.read() + +puts "The input file is #{indata.length} bytes long" + +puts "Does the output file exist? #{File.exists? to_file}" +puts "Ready, hit RETURN to continue, CTRL-C to abort." +STDIN.gets + +output = File.open(to_file, 'w') +output.write(indata) + +puts "Alright, all done." + +output.close() +input.close() diff --git a/test.txt b/test.txt new file mode 100644 index 0000000..6d66b25 --- /dev/null +++ b/test.txt @@ -0,0 +1,3 @@ +To all the people out there. +I say I don't like my hair. +I need to shave it off.