Forum: Ruby Trouble with date

Posted by Pierre-Andre M. (pierreandre_m)
on 2012-12-02 02:19
Im trying to incorporate the date into a directory path

I want to name a folder using the bash command "date +%y%m%d" and then
call that path later on in the script as in:

# This works great
  today = `date +%y%m%d`
  directory = "mkdir -p /Users/me/github/splat/`date +%y%m%d`"
  exec directory


#This part doesnt work

 command = "git clone --mirror https://github.com/org/#{repo_name}.git
/Users/me/github/splat/`date +%y%m%d`/#{repo_name}/"
  exec command

As I understand it when the backticks are used it opens a sub shell, how
can I get that directory name?
Posted by tamouse mailing lists (Guest)
on 2012-12-02 03:14
(Received via mailing list)
On Sat, Dec 1, 2012 at 7:19 PM, Pierre-Andre M. <lists@ruby-forum.com> 
wrote:
>
> Posted via http://www.ruby-forum.com/.
>

Seems to be going a long way 'round something pretty simple.

today = Time.now.strftime("%Y%m%d")
save_path = "/Users/me/github/splat/#{today}"
system("mkdir -p #{save_path}")

# ... later

system("git clone --mirror https://github.com/org/#{repo_name}.git
#{save_path}/#{repo_name}")

Adjust scope on variables as necessary...
Posted by Pierre-Andre M. (pierreandre_m)
on 2012-12-02 03:35
Thank you! That worked great
Posted by unknown (Guest)
on 2012-12-02 09:32
(Received via mailing list)
Am 02.12.2012 03:14, schrieb tamouse mailing lists:
> Seems to be going a long way 'round something pretty simple.
>
> today = Time.now.strftime("%Y%m%d")
> save_path = "/Users/me/github/splat/#{today}"
> system("mkdir -p #{save_path}")

You can create the directories without relying on shell commands:

require 'fileutils'
FileUtils.mkdir_p(save_path)
Posted by 7stud -- (7stud)
on 2012-12-02 09:38
> tamouse mailing lists wrote in post #1087485:
> On Sat, Dec 1, 2012 at 7:19 PM, Pierre-Andre M. <lists@ruby-forum.com>
> wrote:
>
> Seems to be going a long way 'round something pretty simple.
>
> today = Time.now.strftime("%Y%m%d")
> save_path = "/Users/me/github/splat/#{today}"
>
> system("mkdir -p #{save_path}")
>

require 'fileutils'
FileUtils.mkdir_p(save_path)
Posted by tamouse mailing lists (Guest)
on 2012-12-04 04:41
(Received via mailing list)
On Sun, Dec 2, 2012 at 2:38 AM, 7stud -- <lists@ruby-forum.com> wrote:
>>
>
> FileUtils.mkdir_p(save_path)

\o/

There's almost *always* a way to do something in ruby without
resorting to forking another process.
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
No account? Register here.