How can I get the username of the person who initialised the file in ruby?
I'm using w开发者_如何学编程indows xp. and ruby 1.9.2
Try this:
require 'etc'
File.stat("myfile").uid -> 666 for example
puts 'my file owned by', Etc.getpwuid(uid).name
You can try %x{ECHO USERNAME}.chomp
(I can't verify that this will work, as I cannot recall the variable in windows that is the username)
This worked for me in the end.
require 'win32ole'
network=WIN32OLE.new("Wscript.Network")
user = network.username
puts user
精彩评论