0

I want to create a hidden folder for logging information in Ruby, is there a way I can create a hidden folder, and keep it locked with a password, while at the same time logging information to a file inside of it?

Example:

module LogEmail 
  def log(email)
    username = Etc.getlogin
    Dir.mkdir <hidden-dir> unless File.Exists?(<hidden-dir>)

    separator = "[#{Date.today} #{Time.now.strftime('%T')}] ----------"
    File.open("c:/users/#{username}/<hidden-folder>/<log>", 'a+') { |s| s.puts(separator, email) }
  end
end

Is this possible?

13aal
  • 1,634
  • 1
  • 21
  • 47
  • It appears you're on Windows. Ruby's Dir class can create folders and you can set a folder's attributes. You'll need to figure out what the permissions need to be that trigger the OS's locking with a password part as that's not something Ruby will do. – the Tin Man Jun 03 '16 at 17:55
  • @theTinMan Is there no way I can set the attributes from the script itself? – 13aal Jun 03 '16 at 17:58
  • Yes, that's what I said. You could also read the documentation, which says so too. – the Tin Man Jun 03 '16 at 18:06
  • @theTinMan That's incorrect, it might not be `ruby` but it is possible if you call a shell command.. – 13aal Jun 03 '16 at 20:57
  • I said Ruby *CAN* set attributes for a folder, we do it all the time on *nix. Windows affects what languages can do, but it still should be possible to do via Ruby without needing a shell command. Ruby will NOT manage watching a folder and requiring a password unless you wrote code to do it, and then it'd be easy to defeat by stopping that process. Requiring a password to access a folder is an OS level task. – the Tin Man Jun 03 '16 at 21:08

1 Answers1

1

I succeeded in creating a hidden folder using a shell command.

module LogEmail 
  def log(email)
    username = Etc.getlogin
    dir = "c:/users/#{username}/log"
    if File.exists?(dir)
      separator = "[#{Date.today} #{Time.now.strftime('%T')}] ----------"
      File.open("#{dir}/email_log.LOG", 'a+') { |s| s.puts(separator, email) }
    else
      Dir.mkdir(dir)
      `attrib +h #{dir}` #<= Creates a hidden folder.
      separator = "[#{Date.today} #{Time.now.strftime('%T')}] ----------"
      File.open("#{dir}/email_log.LOG", 'a+') { |s| s.puts(separator, email) }
    end  
  end
end
13aal
  • 1,634
  • 1
  • 21
  • 47