question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Get-Item ./.hidden-file fails with "Could not find item"

See original GitHub issue

This behavior is on macOS 11.3.

Steps to reproduce

> Get-Item ~/.profile

Expected behavior

    Directory: /Users/nimazzuc

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-----           4/28/2021 12:25 PM            107 .profile

Actual behavior

Get-Item: Could not find item /Users/nimazzuc/.profile.

Environment data

WSManStackVersion = 3.0
PSEdition = Core
Platform = Unix
PSCompatibleVersions = 1.0 2.0 3.0 4.0 5.0 5.1.10032.0 6.0.0 6.1.0 6.2.0 7.0.0 7.1.3
GitCommitId = 7.1.3
OS = Darwin 20.4.0 Darwin Kernel Version 20.4.0: Fri Mar  5 01:14:02 PST 2021; root:xnu-7195.101.1~3/RELEASE_ARM64_T8101
PSRemotingProtocolVersion = 2.3
SerializationVersion = 1.1.0.1
PSVersion = 7.1.3

Additionally, the Mode thing is weird, shouldn’t that show the unix file mode?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:17 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
strega-nilcommented, Apr 29, 2021

This is… very weird to me, but fair enough. I still think it’s a bug (or at least a thing that should be changed), since hidden files aren’t “different” from regular files on unices.

3reactions
strega-nilcommented, May 1, 2021

Yeah, the fact that Get-Item requires -Force to “find” a hidden file just means that one should always pass -Force to Get-Item, since:

function Get-JsonElement {
  [CmdletBinding()]
  Param([Parameter(Mandatory)][String]$Path, [Parameter(Mandatory)][String]$JPointer)

  $File = Get-Item $Path
  ...
}

this is entirely reasonable code to write; additionally:

> Get-JsonElement .config.json '.foo.bar'

is also entirely reasonable code to write. There is no reason that putting these two bits of code together should fail, assuming .config.json exists, yet the default is that it does fail with a File Not Found error (which is… a very odd error, I must say).

EDIT: I would also argue that the behavior makes no sense on Windows either; why does Get-Item ~/AppData fail. That is very, very weird behavior.

Read more comments on GitHub >

github_iconTop Results From Across the Web

6 Ways to Fix the “Could Not Find This Item” Deletion Error ...
1. Restart Windows Explorer · Right-click Start on the Taskbar and select Task Manager. · In the Processes tab, select Windows Explorer and...
Read more >
Powershell Get-Item not working on some directories like ...
The AppData directory has the hidden attribute set: PS C:\> attrib $env:USERPROFILE\AppData H C:\Users\username\AppData.
Read more >
Could not find this item while deleting a folder.
I tried refreshing file explorer, used command prompt (it says system cannot find the path specified though I directly copied the path from ......
Read more >
Fix “Could Not Find This Item” When Deleting in Windows
The message reads “could not find this item” and it prevents you from deleting the file. It's pretty obvious you're trying to delete...
Read more >
Unable to compress hidden files with Compress-Archive #66
Get-Item : Could not find item C:\Compress-Archive test\Input\2.txt. At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\Microsoft.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found