utime permission denied in windows 7 when call FileUtils.touch(f)

蹲街弑〆低调 提交于 2019-12-13 03:34:40

问题


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)

回答1:


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)


来源:https://stackoverflow.com/questions/20767883/utime-permission-denied-in-windows-7-when-call-fileutils-touchf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!