How to set permission '777' to dir?

hello, I’ve some question when I want to create new folder with
permission ‘777’.

I use following code

FileUtils.mkdir 'tmp', :mode => 0777

and the result is in the picture. it show me ‘775’ what’s wrong with
this code?

Pat K. wrote:

hello, I’ve some question when I want to create new folder with
permission ‘777’.

I use following code

FileUtils.mkdir 'tmp', :mode => 0777

and the result is in the picture. it show me ‘775’ what’s wrong with
this code?

That’s because, on POSIX systems, the permissions of a new
file/directory are set to what you asked for (0777 in your case) minus
something called umask. Google for “umask” to learn about it.

If you really want 0777, do File.chmod() (or FileUtils.chmod()) after
creating the file.

I try FileUtils.chmod() after create new file but it still has permision
‘775’ :’(

it’s show me
40755
40755
??

oh I try in Linux with the same code it’s
40755
40777

what’s wrong with window7? it has another way to do it :’(

Try running this script:

begin
Dir.mkdir(“footst”)
puts File.stat(“footst”).mode.to_s(8)
File.chmod(0777, “footst”)
puts File.stat(“footst”).mode.to_s(8)
ensure
Dir.rmdir(“footst”)
end

For me (under Linux) it shows:
40755
40777

Does it not for you?

The alternative solution (which is probably not threadsafe) is to modify
umask, like this:

begin
old_umask = File.umask
File.umask 0
Dir.mkdir(“footst”)
puts File.stat(“footst”).mode.to_s(8)
Dir.rmdir(“footst”)
ensure
File.umask old_umask
end

Pat K. wrote:

oh I try in Linux with the same code it’s
40755
40777

what’s wrong with windows7? it has another way to do it :’(

You mean to say that Windows 7 has the unixy owner/group/world
permissions for files? Wow.