0

I'm working with ruby 2.0 on windows 7 (unfortunately I have to) and have issue with this code:

FileUtils.touch(file)

This code is needed to update file.ctime (which probably will have problems too) So, when files is processed I 'touch' them and not processing them in next iteration.

How can I deal with it error?

ruby_path/fileutils.rb:1137:in 'utime': Permission denied 'path_to_file' Errno::EACCES
'block in touch'
'each'
'touch'

example:

file = File.new('file_path')
FileUtils.mkdir_p(path)
FileUtils.cp(file.path, path)
FileUtils.touch(file)
Extazystas
  • 488
  • 2
  • 11
  • Reading your [task in your original question](http://stackoverflow.com/questions/20751296/have-to-run-ruby-script-on-windows-7-and-got-permission-denied-eacces): For what do you need a touch? Have you a MWE? Which file do you want to touch? – knut Dec 26 '13 at 09:31
  • I need a touch to update file timestamp. Next I compare file timestamp with a program timestamp to check if this file was already processed. For now I found a 'dirty' solution that works on windows: File.open(file, 'a').print ' ' – Extazystas Dec 26 '13 at 19:28

1 Answers1

0

I tested with ruby 1.9 and 2.0. FileUtils.touch works without problems.

Can you provide a MWE. Did you check the permissions on the file you want to check.

Especially: Are you sure, you don't touch a directory?

If you don't want to check for directories, you may extend FileUtils by FileUtils.save_touch:

require 'fileutils'    
module FileUtils
  def self.save_touch(fpath)
    FileUtils.touch(fpath) unless File.directory?(fpath)
  end
end

FileUtils.save_touch(Dir.pwd)

After update of question:

FileUtils.touch has one parameter: a file name or path to a file.

You have to adapt your example:

file = File.new('file_path')
FileUtils.mkdir_p(path)
FileUtils.cp(file.path, path)
FileUtils.touch(file.path)
knut
  • 27,320
  • 6
  • 84
  • 112
  • Anyway - windows don't recognize file.ctime as 'file changed time'. file.ctime on windows = 'file creation time' and this is why I change behaviour to deal with mtime – Extazystas Dec 27 '13 at 09:05