[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Creating Files

Andy Ferra

2/24/2006 2:53:00 AM

Could someone please tell me how to create a new file?

Thank you.

2 Answers

Yuu

2/24/2006 3:25:00 AM

0

Andy Ferra wrote:
> Could someone please tell me how to create a new file?

You could use FileUtils.touch or just File.open a filename
in write-mode. You can take a look at the documentation for
those classes by typing

ri FileUtils
ri File

On your command-line.

> Thank you.


E

--
Posted via http://www.ruby-....


Tony Mobily

2/24/2006 4:59:00 AM

0

Hi,

For an empty file, I guess the easiest way would be:

# Create a new file and write on it
#
begin
f=File::open("test.txt","w")
rescue SystemCallError
puts "Problem with File::open #1"
#... something went wrong...
else
f.close
end


# The file will be closed afterwards
#
begin
File::open("/etc/test.txt","w") do | f |
# Do somethinf with "f" ...
end
rescue SystemCallError
# The file can't be created
puts "Problem with File::open #2"
end


# If all you want is create an empty file...
#
begin
File::open("test.txt","w") {}
rescue SystemCallError
# The file can't be created
puts "Problem with File::open #3"
end

read "ri IO::open" for more info!

Merc.

On 24/02/2006, at 10:53 AM, Andy Ferra wrote:

> Could someone please tell me how to create a new file?
>
> Thank you.
>