0

Am writing a script which creates a directory but when i tried (Ruby script running on windows)

destination = "path to the folder"

FileUtils.mkdir_p destination

it gives me an error saying Permission Denied (Errno::EACCES) at mkdir_p

Any help is appreciated . Thank you

meher
  • 49
  • 5
  • Well … do you *have* the required permissions? – Jörg W Mittag Jun 09 '17 at 08:45
  • Yes, I have given all the permissions , i redone everything from scratch but still that issue persists, looks like that has something to do with the code and how am writing but am not sure – meher Jun 09 '17 at 14:24

1 Answers1

2

open your cmd terminal with administrator privileges, and then run the script again. It seems like your folder is in a place that need admin privileges, so you can create it. Also add it to your script:

require 'win32ole'

shell = WIN32OLE.new('Shell.Application')
shell.ShellExecute('path_to_ruby_program', nil, nil, 'runas')

And see this two questions:

Run ruby script in elevated mode

Detect if running with administrator privileges under Windows XP

developer_hatch
  • 15,898
  • 3
  • 42
  • 75
  • I tried doing that , i have given all the permissios or required permissions but still that is a problem , – meher Jun 09 '17 at 14:24
  • destination = "\\\\server\\usershares\\#{username}\\Documents\\"+userid.to_s+"" FileUtils.mkdir_p destination – meher Jun 09 '17 at 14:30
  • @meher I updated the answer for you, add it to the script, and don't forget voting and accepting if you liked :) – developer_hatch Jun 09 '17 at 14:30
  • looks like it was fixed by giving full control to that folder, anyways i will use the solution for my future tasks , Thank you – meher Jun 14 '17 at 22:06
  • Sure, i did this time as well – meher Jun 14 '17 at 22:24
  • @meher no problem! I have always loved to help, if the answer was useful don't forget in the future to accept (with the check box top left in the answer the ✓ simbol) – developer_hatch Jun 14 '17 at 22:32