# How to append the time stamp in before file name

**URL:** <https://www.ruby-forum.com/t/how-to-append-the-time-stamp-in-before-file-name/188529>\
**Category:** Ruby\
**Created:** [May 13, 2010, 12:31pm UTC](https://www.ruby-forum.com/t/how-to-append-the-time-stamp-in-before-file-name/188529 "2010-05-13T12:31:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sweetzubair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@sweetzubair](https://www.ruby-forum.com/u/sweetzubair)\
**Post date:** [May 13, 2010, 12:31pm UTC](https://www.ruby-forum.com/t/how-to-append-the-time-stamp-in-before-file-name/188529/1 "2010-05-13T12:31:25Z")

</div>

Hello all,

i write code for create log file and i want to append the time stamp  
before file name.  
like: 0513\_1552\_05.logger.txt

plz help me…!!!

require ‘watir’  
include Watir  
require ‘logger’  
time\_stamp\_s = Time.new.strftime(‘%m%d\_%H%M\_%S’)  
puts time\_stamp\_s  
a=“logger.txt”  
log = Logger.new( ‘C:\test#{time\_stamp\_s}’+‘.txt’, ‘daily’ )  
if(  
ie=Watir::IE.start(“[http://vision.vendormate.net/vm/login.do](http://vision.vendormate.net/vm/login.do)”))  
if(ie.contains\_text(“Login”))  
log.debug “login page open  
successfully…!!!”  
else  
log.debug “login page not found…!!!”  
break  
end  
end  
if(contents = File.read(“c:/test/test.txt”))  
log.debug “Read text file test.txt”  
else  
log.debug “File not avilable”  
break  
end  
data = contents.map do |line|  
line.chomp.split(“=”)[1]  
end  
if(ie.text\_field(:name,“userId”).set(data[0]))  
log.debug “fill the username in username text field”  
else  
log.debug “username not avilable”  
end

```
    if(ie.text_field(:name,"password").set(data[1]))
          log.debug "fill the password in password text field"
    else
          log.debug "Password not avilable"
    end

```

ie.button(:name,“Submit”).click()  
if(ie.contains\_text(“My statistics”))  
log.debug “Login Successfully…!!!\n”  
else  
log.debug “Login Failed…!!!\n”  
end

---

<div class="post-metadata">

**Author:** ![sweetzubair](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/7feea3/32.png) [@sweetzubair](https://www.ruby-forum.com/u/sweetzubair)\
**Post date:** [May 13, 2010, 4:08pm UTC](https://www.ruby-forum.com/t/how-to-append-the-time-stamp-in-before-file-name/188529/2 "2010-05-13T16:08:59Z")

</div>

Hi

On Thu, May 13, 2010 at 7:31 AM, KingMaker KingMaker  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> puts time\_stamp\_s  
> a=“logger.txt”  
> log = Logger.new( ‘C:\test#{time\_stamp\_s}’+‘.txt’, ‘daily’ )

You get string interpolation when using double quotes. See for other  
cases [Ruby | zenspider.com | by ryan davis](http://www.zenspider.com/Languages/Ruby/QuickRef.html#6)  
So try with “C:\test#{time\_stamp\_s}.txt”
