[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

creating directory and zipping it

Raju Aralikatti

1/8/2008 5:47:00 AM

hi,
can anyone help me.

I want to create a folder, create another file of .url type and save the
url file in the folder and zip the folder. I am sending the code which
I have written and I am getting following error. "No such file or
directory - InstitutionShortcut"

dir_name = Dir.new("InstitutionShortcut")
file_path =
"#{RAILS_ROOT}/public/test/#{dir_name}/Isabel-#{@institutions.institution_name}.url"
f = File.new(file_path, "w")
content = ""
content += "[InternetShortcut]\n"
content += "URL=http://192.168.1.233:5555/index....
content += "passcode="+@institution.passcode+"\n"
content += "IconFile=http://192.168.1.233:5555/f...\n"
content += "IconIndex=1\n"
content += "Modified=30B027EB835EC40198"
f.write( content )
f.close
dir_name.zip

can anyone help me

Thanks in advance
--
Posted via http://www.ruby-....

16 Answers

Matt Todd

1/8/2008 6:16:00 AM

0

http://rake.rubyforge.org/svn/trunk/lib/rake/pack...

Has some code for packing things up.

Matt

Raju Aralikatti

1/8/2008 6:42:00 AM

0

Matt Todd wrote:
> http://rake.rubyforge.org/svn/trunk/lib/rake/pack...
>
> Has some code for packing things up.
>
> Matt

hi Matt,
I m new to ruby, can you tell me how to

1. create directory using ruby.
2. Then create a file.
3. Put the newly created file in the new directory.
4. zip the directory.
--
Posted via http://www.ruby-....

Andrew Timberlake

1/8/2008 7:20:00 AM

0

Raju

1. Create a directory
d =3D Dir.mkdir('test')
#creates a directory named 'test'
2. Create a file
File.open('test/test.txt', 'w') { |f| puts 'Hello World' }
#creates a new file named test.txt inside the directory 'test' and =
writes 'Hello World' into the file
3. This is done in the above code by creating the new file inside the =
directory itself
4. Zip the directory
%x{zip -r test.zip test}
#This executes the zip command of the underlying operating system =
(I'm using Linux) and creates a zip file named test.zip containing the =
directory 'test' (the -r flag makes the zipping recursive)
#If you can't use that (on Windows), try rubyzip.sourceforge.net/ - =
I have not used it but I found it via Google search

Hope that helps

Regards

Andrew Timberlake
andrew@andrewtimberlake.com
082 415 8283
skype: andrewtimberlake

"I have never let my schooling interfere with my education."
--Mark Twain


-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf =
Of Raju Aralikatti
Sent: 08 January 2008 08:42 AM
To: ruby-talk ML
Subject: Re: creating directory and zipping it

Matt Todd wrote:
> http://rake.rubyforge.org/svn/trunk/lib/rake/pack...
>=20
> Has some code for packing things up.
>=20
> Matt

hi Matt,
I m new to ruby, can you tell me how to

1. create directory using ruby.
2. Then create a file.
3. Put the newly created file in the new directory.
4. zip the directory.
--=20
Posted via http://www.ruby-....


!DSPAM:3,47831c5e223171609211822!





Raju Aralikatti

1/8/2008 9:47:00 AM

0

thanks Andrew,
The code which you sent is working fine, I am also using a Linux
machine, But the it is not ziping the folder. Is there anything else I
can use.
--
Posted via http://www.ruby-....

Raju Aralikatti

1/8/2008 9:51:00 AM

0

and also Andrew I want to overwrite the directory if the newly created
directory has the same name of the existing directory.
--
Posted via http://www.ruby-....

Andrew Timberlake

1/8/2008 11:53:00 AM

0

Raju

If you run the zip code in irb, what output do you get?
I get the following:
Irb(main):001:0> %x{zip -r test.zip test}
=3D> " adding: test/ (stored 0%)\n adding: test/test.txt (stored 0%)\n"

Andrew Timberlake
andrew@andrewtimberlake.com
082 415 8283
skype: andrewtimberlake

"I have never let my schooling interfere with my education."
--Mark Twain


-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf =
Of Raju Aralikatti
Sent: 08 January 2008 11:47 AM
To: ruby-talk ML
Subject: Re: creating directory and zipping it

thanks Andrew,
The code which you sent is working fine, I am also using a Linux=20
machine, But the it is not ziping the folder. Is there anything else I=20
can use.
--=20
Posted via http://www.ruby-....


!DSPAM:3,4783479a35767204610105!





Andrew Timberlake

1/8/2008 11:53:00 AM

0

Raju

By overwrite the directory, I assume you want to delete the contents of =
the directory if it exists, you can do that as follows:
if File.exists?('test') && File.directory?('test')
Dir['test/**/*'].reverse.each { |path| if File.file?(path) then =
File.delete(path) else Dir.rmdir(path) end }
else
Dir.mkdir('test')
end

Andrew Timberlake
andrew@andrewtimberlake.com
082 415 8283
skype: andrewtimberlake

"I have never let my schooling interfere with my education."
--Mark Twain


-----Original Message-----
From: list-bounce@example.com [mailto:list-bounce@example.com] On Behalf =
Of Raju Aralikatti
Sent: 08 January 2008 11:51 AM
To: ruby-talk ML
Subject: Re: creating directory and zipping it

and also Andrew I want to overwrite the directory if the newly created=20
directory has the same name of the existing directory.
--=20
Posted via http://www.ruby-....


!DSPAM:3,4783489239791012915643!





Satish

2/17/2014 5:53:00 PM

0

On Monday, February 17, 2014 9:08:53 AM UTC-8, rst9 wrote:
> On Monday, February 17, 2014 12:02:34 AM UTC-8, forc...@gmail.com wrote:
>
>
>
> Watch it on:
>
> http://www.cbsnews.com/news/f-35-joint-strike-fighter-6...
>
>
>
> And see for yourself.
>
>
>
> No one can say which is the best until an actual war fight.

Yale Guen Mar, as far as you are concerned, your middle fingers were the best (till they got infected) when you used them as missiles to penetrate assholes of pigs in hog farms owned by your Hmong neighbors in Merced.

Nut now you are about to lose your middle fingers which have become infected beyond redemption.

Go to Cambodia ASAP to see if you can save your middle fingers with alternate medical treatment.

Brad Guth

2/17/2014 7:01:00 PM

0

On Monday, February 17, 2014 10:02:18 AM UTC-8, Fisjono wrote:
> On 2/17/2014 9:08 AM, rst9 wrote:
>
> > On Monday, February 17, 2014 12:02:34 AM UTC-8, forc...@gmail.com wrote:
>
> >
>
> > Watch it on:
>
> > http://www.cbsnews.com/news/f-35-joint-strike-fighter-6...
>
> >
>
> > And see for yourself.
>
> >
>
> > No one can say which is the best until an actual war fight.
>
> >
>
>
> DRONES that cannot be detected by the most sophisticated radar system is
>
> the BEST!

And you could buy and afford to operate at least a dozen of those for every F35 (especially once the true all-inclusive costs are taken into account).

Fat Wo

2/17/2014 7:32:00 PM

0

Not only that it is the small and undetected easily, it can travel
"relentlessly" and hovering the skies for hours without the worry of
crashing into the ground.

If it was F35 plane, where the pilot would have been scared out of his pant
looking intently at the fuel gauge in front of him to check if there was
enough fuel for him to go home or not.

And in course of his panic, he might just offload his armaments, and sped
home without accurately checked in delivering to its targets..





"Fisjono" wrote in message
news:K8sMu.67559$rf1.13639@en-nntp-02.dc1.easynews.com...

On 2/17/2014 9:08 AM, rst9 wrote:
> On Monday, February 17, 2014 12:02:34 AM UTC-8, forc...@gmail.com wrote:
>
> Watch it on:
> http://www.cbsnews.com/news/f-35-joint-strike-fighter-6...
>
> And see for yourself.
>
> No one can say which is the best until an actual war fight.
>

DRONES that cannot be detected by the most sophisticated radar system is
the BEST!