X Tutup
The Wayback Machine - https://web.archive.org/web/20240110133324/https://github.com/PowerShell/PowerShell/issues/20929
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a -Force switch to Convert-Path and Resolve-Path so as to also support hidden files. #20929

Open
mklement0 opened this issue Dec 14, 2023 · 4 comments · May be fixed by #20981
Open

Add a -Force switch to Convert-Path and Resolve-Path so as to also support hidden files. #20929

mklement0 opened this issue Dec 14, 2023 · 4 comments · May be fixed by #20981
Labels
In-PR Indicates that a PR is out for the issue Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module

Comments

@mklement0
Copy link
Contributor

mklement0 commented Dec 14, 2023

Summary of the new feature / enhancement

Currently, both Convert-Path and Resolve-Path only ever report non-hidden files as matching a given wildcard pattern.

In order to also support hidden files, a -Force switch should be added, analogous to Get-Item and Get-ChildItem.

E.g., on Unix-like platforms:

# Ditto for Resolve-Path
Convert-Path ~/.bash*

This currently produces NO output, because .-prefixed files and directories are considered hidden on Unix-like platforms.
Desired output (for example):

/Users/jdoe/.bash_sessions
/Users/jdoe/.bash_history
/Users/jdoe/.bash_profile
/Users/jdoe/.bashrc

Note: The problem arises only with wildcard patterns - literal paths are found.

Proposed technical implementation details (optional)

No response

@mklement0 mklement0 added Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. labels Dec 14, 2023
@StevenBucher98 StevenBucher98 added the WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module label Dec 18, 2023
@ArmaanMcleod
Copy link
Contributor

This sounds like a great enhancement 👍

It was always interesting how only Get-ChildItem had a -Hidden parameter which only displayed hidden files. If you also wanted non-hidden files you would also need to use -Force.

Makes sense to use -Force for consistency to include hidden files for all cmdlets.

@ArmaanMcleod
Copy link
Contributor

I noticed as well on Ubuntu this seems to only be an issue with wildcards:

12-21 18:37:36 ~/git-repos/PowerShell [master ≡]> Convert-Path ./.gitignore
/home/armaan/git-repos/PowerShell/.gitignore
12-21 18:37:52 ~/git-repos/PowerShell [master ≡]> Convert-Path ./.git*
12-21 18:37:55 ~/git-repos/PowerShell [master ≡]>
12-21 18:37:55 ~/git-repos/PowerShell [master ≡]> Resolve-Path ./.gitignore

Path
----
/home/jdoe/git-repos/PowerShell/.gitignore

12-21 18:40:39 ~/git-repos/PowerShell [master ≡]> Resolve-Path ./.git*
12-21 18:40:42 ~/git-repos/PowerShell [master ≡]>

On Windows it works as expected:

12-21 18:39:15 ~\git-repos\PowerShell [master ≡]> Convert-Path .\.gitignore
C:\Users\jdoe\git-repos\PowerShell\.gitignore
12-21 18:39:20 ~\git-repos\PowerShell [master ≡]> Convert-Path .\.git*
C:\Users\jdoe\git-repos\PowerShell\.github
C:\Users\jdoe\git-repos\PowerShell\.gitattributes
C:\Users\jdoe\git-repos\PowerShell\.gitignore
12-21 18:39:23 ~\git-repos\PowerShell [master ≡]> Resolve-Path .\.gitignore

Path
----
C:\Users\jdoe\git-repos\PowerShell\.gitignore

12-21 18:40:05 ~\git-repos\PowerShell [master ≡]> Resolve-Path .\.git*

Path
----
C:\Users\jdoe\git-repos\PowerShell\.github
C:\Users\jdoe\git-repos\PowerShell\.gitattributes
C:\Users\jdoe\git-repos\PowerShell\.gitignore

@mklement0
Copy link
Contributor Author

Thanks, @ArmaanMcleod.

Good point about only wildcard expressions being affected (I've updated the initial post to clarify.)

Note that .-prefixed files aren't necessarily hidden on Windows, which explains why even wildcard-based matching found it. There, it is the Hidden attribute that matters, so if you hide, say, .\.gitignore with attrib -h .\.gitignore, Convert-Path .\.git* will no longer match it.

As an aside:

@mklement0
Copy link
Contributor Author

mklement0 commented Dec 28, 2023

I forgot that years ago I had asked for the same, only more comprehensively:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
In-PR Indicates that a PR is out for the issue Issue-Enhancement the issue is more of a feature request than a bug Needs-Triage The issue is new and needs to be triaged by a work group. WG-Cmdlets-Management cmdlets in the Microsoft.PowerShell.Management module
Projects
None yet
3 participants
X Tutup