Method: PSWindows::Exec#modified_at

Defined in:
lib/beaker/host/pswindows/exec.rb

#modified_at(file, timestamp = nil) ⇒ Object

Update ModifiedDate on a file

Parameters:

  • file (String)

    Path to the file

  • timestamp (String) (defaults to: nil)

    Timestamp to set



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/beaker/host/pswindows/exec.rb', line 43

def modified_at(file, timestamp = nil)
  require 'date'
  time = timestamp ? DateTime.parse("#{timestamp}") : DateTime.now

  result = execute("powershell Test-Path #{file} -PathType Leaf")

  execute("powershell New-Item -ItemType file #{file}") if result.include? 'False'
  execute("powershell (gci #{file}).LastWriteTime = Get-Date " \
          "-Year '#{time.year}'" \
          "-Month '#{time.month}'" \
          "-Day '#{time.day}'" \
          "-Hour '#{time.hour}'" \
          "-Minute '#{time.minute}'" \
          "-Second '#{time.second}'")
end