Create a folder with the current time as a name

I am trying to write a simple backup script in Ruby that copies a folder to a specific directory with a timestamp in its name. My code (simplified):

require 'Fileutils.rb'
time = Time.now
FileUtils.cp_r "C:/somefolder", "D:/somefolder_backup_#{time}" 

But I keep getting

`fu_mkdir': Unknown error - mkdir failed (SystemCallError)

The same thing happens if I just want to create a folder with the current time in it:

FileUtils.mkdir "C:/somefolder_#{time}"

This doesn't seem to be a privilege issue, unless I specify # {time} -thing, it works fine.

Any advice is appreciated.

+3
source share
2 answers

, , Windows ( Ubuntu). , , , , :

require 'Fileutils.rb'
time = Time.now.strftime("%Y%m%d%H%M%S")
FileUtils.cp_r "C:/somefolder", "D:/somefolder_backup_#{time}" 
+8

, Time.now, , .

Daniel .

+1

Source: https://habr.com/ru/post/1770371/


All Articles