3

By accident, I recently tried running Get-Content on a directory. I'd initially thought it was a file because it was named very similarly to a common file I'd expected to be in the location. So I was further confused when I was given an "Access Denied" error in a location where I should have full control.

Of course, I eventually realized my mistake. Once I actually pointed Get-Content at some files in the same area, or in subfolders of that path, it worked fine. But the error still strikes me as odd. At the very least, I figure it would be more user-friendly and sensible to present an error that actually says (albeit more politely) "That's not a file you're trying to look at, genius!".

Why does "Access Denied" make sense in this context?

1
  • 2
    It not PowerShell returns "Access Denied", but Windows do so. Try notepad SomeDirectory and you will get same error.
    – user364455
    Mar 5, 2015 at 14:06

1 Answer 1

1

The reason for this is that the process - be it PowerShell, Notepad, etc tries to open the directory as if it were a file.

Sine "File Permissions" can't be read for a file (I know NTFS permissions can be set and look the same, but under the hood they aren't) - it generates an "Access Denied" message which is passed to whatever program you tried to use.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .