Can I create directories with dynamic names on run time using Ruby1.9?

I have to download files from the web over several requests. The
downloaded files for each request have to be put in a folder with the
same name as the request number.

For example:

My script is now running to download files for request number 87665. So
all the downloaded files are to be put in the destination folder Current
Download\Attachment87665. So how do I do that?

Destination folder: Current Download is fixed. only need to create
Attachmentxxxxxx dynamically, where xxxxxx any request number.

This is Python version of code: but I want it in a Ruby, just for your
reference to understand what I am looking for

request_number = 82673

base dir

_dir = “D:\Current Download”

create dynamic name, like “D:\Current Download\Attachment82673”

_dir = os.path.join(_dir, ‘Attachment%s’ % request_number)

create ‘dynamic’ dir, if it does not exist

if not os.path.exists(_dir):
os.makedirs(_dir)

Subject: Can I create directories with dynamic names on run time using
Ruby1.9?
Date: Thu 10 Jan 13 04:46:05PM +0900

Quoting Arup R. ([email protected]):

My script is now running to download files for request number 87665. So
all the downloaded files are to be put in the destination folder Current
Download\Attachment87665. So how do I do that?

Function FileUtils#mkdir_p makes sure that all intermediate
directories are created when creating a path.

Carlo

Carlo E. Prelz wrote in post #1091698:

Subject: Can I create directories with dynamic names on run time using
Ruby1.9?
Date: Thu 10 Jan 13 04:46:05PM +0900

Quoting Arup R. ([email protected]):

My script is now running to download files for request number 87665. So
all the downloaded files are to be put in the destination folder Current
Download\Attachment87665. So how do I do that?

Function FileUtils#mkdir_p makes sure that all intermediate
directories are created when creating a path.

Carlo

Can I have a simple snippet for that, I am totally new to Ruby. I have
Ruby 1.9.3 installed in my PC(windows 7)

require ‘fileutils’

path = “string to the folder”
FileUtils.mkdir_p(path)


Carlos A.

Control engineering
Polytechnic School, University of So Paulo, Brazil
Computer engineering
Embry-Riddle Aeronautical University, USA

2013/1/10 Arup R. [email protected]

Subject: Re: Can I create directories with dynamic names on run time
using Ruby1.9?
Date: Thu 10 Jan 13 04:55:12PM +0900

Quoting Arup R. ([email protected]):

Can I have a simple snippet for that, I am totally new to Ruby. I have
Ruby 1.9.3 installed in my PC(windows 7)

You may be new to ruby, but in order to write code you should know how
to call a method of a class…

This works on Linux (I have no windows):

require ‘fileutils’
FileUtils::mkdir_p(’/a/b/c/d’)

This results (if you have the appropriate rights) in the creation of
these directories:

/a
/a/b
/a/b/c
/a/b/c/d

Carlo

Carlos A. wrote in post #1091700:

require ‘fileutils’

path = “string to the folder”
FileUtils.mkdir_p(path)


Carlos A.

Control engineering
Polytechnic School, University of So Paulo, Brazil
Computer engineering
Embry-Riddle Aeronautical University, USA

2013/1/10 Arup R. [email protected]

have you watched my Python snippet? Look at that how it is
concatenating and checking if that file exist or not? then dynamically
creating the folders with that name.