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)
on 2013-01-10 08:46
on 2013-01-10 08:51
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 Rakshit (lists@ruby-forum.com): > 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
on 2013-01-10 08:55
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 Rakshit (lists@ruby-forum.com): > >> 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)
on 2013-01-10 09:00
require 'fileutils' path = "string to the folder" FileUtils.mkdir_p(path) ----- Carlos Agarie Control engineering Polytechnic School, University of So Paulo, Brazil Computer engineering Embry-Riddle Aeronautical University, USA 2013/1/10 Arup Rakshit <lists@ruby-forum.com>
on 2013-01-10 09:03
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 Rakshit (lists@ruby-forum.com): > 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
on 2013-01-10 09:04
Carlos Agarie wrote in post #1091700: > require 'fileutils' > > path = "string to the folder" > FileUtils.mkdir_p(path) > > > ----- > Carlos Agarie > > Control engineering > Polytechnic School, University of So Paulo, Brazil > Computer engineering > Embry-Riddle Aeronautical University, USA > > > 2013/1/10 Arup Rakshit <lists@ruby-forum.com> 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.
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.