简体   繁体   中英

Ruby: rm cannot remove file permissions denied

I am trying to delete a file I created in a ruby script I am using the following to try and delete it;

x = `cmd /c rm c:\\temp\\secret.txt`

File.delete("c:\\temp\\secret.txt")

When I try to delete it I am getting a error for permissions denied. Does anyone know how to solve this problem?

Try adding:

require 'fileutils' 
FileUtils::chmod(0644, "c://temp//secret.txt")
FileUtils.rm '"c://temp//secret.txt", :force => true 

My guess is that Chef is changing the mode to make it hard to read. You can verify this by running ls -l from cygwin or running a stat from inside Ruby

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM