Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > newbie question making a folder with ruby

Reply
Thread Tools

newbie question making a folder with ruby

 
 
Simon Staton
Guest
Posts: n/a
 
      08-13-2009
ok well the program I am in the middle of programming I need it to
generate a folder in the c: when it loads up.

does anyone know how I can do this? and possibly make it with an if
variable so if there is already a folder in the c: called action3d dont
generate one but if there isnt then make one
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Fleck Jean-Julien
Guest
Posts: n/a
 
      08-13-2009
Hello,

2009/8/13 Simon Staton <(E-Mail Removed)>:
> ok well the program I am in the middle of programming I need it to
> generate a folder in the c: when it loads up.
>
> does anyone know how I can do this? and possibly make it with an if
> variable so if there is already a folder in the c: called action3d dont
> generate one but if there isnt then make one


Have a look at Dir.mkdir and File.exist?

Cheers,

--=20
JJ Fleck
PCSI1 Lyc=E9e Kleber

 
Reply With Quote
 
 
 
 
Simon Staton
Guest
Posts: n/a
 
      08-13-2009
Fleck Jean-Julien wrote:
> Have a look at Dir.mkdir and File.exist?
>
> Cheers,


Didnt work for me :s just gave errors. I am codeing ruby in google
sketchup if that helps.

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

 
Reply With Quote
 
Fleck Jean-Julien
Guest
Posts: n/a
 
      08-13-2009
> Didnt work for me :s just gave errors. I am codeing ruby in google
> sketchup if that helps.


What kind of error did you get and what is the code you used ?

--=20
JJ Fleck
PCSI1 Lyc=E9e Kleber

 
Reply With Quote
 
Simon Staton
Guest
Posts: n/a
 
      08-13-2009
Fleck Jean-Julien wrote:
>> Didnt work for me :s just gave errors. I am codeing ruby in google
>> sketchup if that helps.

>
> What kind of error did you get and what is the code you used ?


p File.exists?('~/Documents/fake/nonexistant/directories/new_dir')
#=>false
p Dir.mkdir('~/Documents/fake/nonexistant/directories/new_dir')
#=>0
p File.exists?('~/Documents/fake/nonexistant/directories/new_dir')
#=>true
p Dir.mkdir('~/Documents/fake/nonexistant/directories/new_dir')
#=>:[-1,-1]:[0,0]: File exists -
~/Documents/fake/nonexistant/directories/new_dir (Errno::EEXIST)
p File.exists?('~/Documents/fake/nonexistant/directories/new_dir')
#=>true
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Fleck Jean-Julien
Guest
Posts: n/a
 
      08-13-2009
>>
>> What kind of error did you get and what is the code you used ?

>
> p File.exists?('~/Documents/fake/nonexistant/directories/new_dir')
> #=3D>false
> p Dir.mkdir('~/Documents/fake/nonexistant/directories/new_dir')
> #=3D>0
> p File.exists?('~/Documents/fake/nonexistant/directories/new_dir')
> #=3D>true
> p Dir.mkdir('~/Documents/fake/nonexistant/directories/new_dir')
> #=3D>:[-1,-1]:[0,0]: File exists -
> ~/Documents/fake/nonexistant/directories/new_dir (Errno::EEXIST)
> p File.exists?('~/Documents/fake/nonexistant/directories/new_dir')
> #=3D>true


So, everything is working fine: you just can't call Dir.mkdir on an
existant file. That's why you have to use File.exist? to ensure your
directory is not yet in place:

if File.exist?(dir)
puts "#{dir} already exists !"
else
Dir.mkdir(dir)
end

Cheers,

--=20
JJ Fleck
PCSI1 Lyc=E9e Kleber

 
Reply With Quote
 
Lui Core
Guest
Posts: n/a
 
      08-13-2009
Simon Staton wrote:
> ok well the program I am in the middle of programming I need it to
> generate a folder in the c: when it loads up.
>
> does anyone know how I can do this? and possibly make it with an if
> variable so if there is already a folder in the c: called action3d dont
> generate one but if there isnt then make one


Yet another answer (command line):

ruby -run -e mkdir newdirname

or in rb code:

`ruby -run -e mkdir newdirname`
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Simon Staton
Guest
Posts: n/a
 
      08-14-2009
Lui Core wrote:
> Simon Staton wrote:
>> ok well the program I am in the middle of programming I need it to
>> generate a folder in the c: when it loads up.
>>
>> does anyone know how I can do this? and possibly make it with an if
>> variable so if there is already a folder in the c: called action3d dont
>> generate one but if there isnt then make one

>
> Yet another answer (command line):
>
> ruby -run -e mkdir newdirname
>
> or in rb code:
>
> `ruby -run -e mkdir newdirname`



yeh im using a .rb file to do my codeing. so if I was to put code in
there wanting to make a folder on there c: called temp what would I put.
=) sorry noob to ruby here ^^
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Simon Staton
Guest
Posts: n/a
 
      08-14-2009
To give more of an idea this is the code that I have on the .rb file. it
is a plugin im building for a program called google sketchup.

status = UI.show_inspector "Components"
toolbar = UI::Toolbar.new "Action 3D Toolbar"

cmd = UI::Command.new("Export") {
Sketchup.send_action(21237)
}
cmd.small_icon = "export.png"
cmd.large_icon = "export.png"
cmd.tooltip = "Save Climbing Frame As An Image"
cmd.status_bar_text = "Testing the toolbars class"
cmd.menu_text = "Test"
toolbar = toolbar.add_item cmd
toolbar.show

all that is doing is adding a new toolbar and opening somthing called a
components panel. now is it possible to add code in here that will
create a folder on there C: called temp and if it is already there dont
overwrite it.
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Fleck Jean-Julien
Guest
Posts: n/a
 
      08-14-2009
Hello,

> all that is doing is adding a new toolbar and opening somthing called a
> components panel. now is it possible to add code in here that will
> create a folder on there C: called temp and if it is already there dont
> overwrite it.


Sure.
I'll suppose you are on a UNIX system type (I do not know that sort of
thing on windows, perhaps, it is as simple as changing /temp by
c:/temp or c:\temp)

Just add:

dir =3D "/temp"

if File.exist?(dir)
puts "#{dir} already exists !"
else
Dir.mkdir(dir)
end

Cheers,

--=20
JJ Fleck
PCSI1 Lyc=E9e Kleber

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Ruby Newbie question about app making Lloyd Linklater Ruby 1 06-05-2007 07:20 PM
Re: A fresh new approach to making making online Fakename Computer Information 0 11-18-2005 02:10 AM
Error after making a folder an application Andy Sutorius ASP .Net 3 02-15-2005 05:21 AM
Making new Flavors : Making a custom transferhandler for and drop applications ebby83@gmail.com Java 5 01-12-2005 11:10 AM
making a folder in Windows don Computer Support 2 07-02-2003 09:22 PM



Advertisments