Skip to content

Allow use of long paths - #3960

Merged
Jason Shirk (lzybkr) merged 2 commits into
PowerShell:masterfrom
jeffbi:item-exists-3891
Jun 8, 2017
Merged

Allow use of long paths#3960
Jason Shirk (lzybkr) merged 2 commits into
PowerShell:masterfrom
jeffbi:item-exists-3891

Conversation

@jeffbi

@jeffbi jeffbi commented Jun 7, 2017

Copy link
Copy Markdown

Fixes #3891

When calling Windows native API to determine if an item exists, ensure the path is prepended with \\?\ to allow for paths > 260 characters.

When calling Windows native API to determine if an item exists,
ensure the path is prepended with "\\?\" to allow for long paths.
internal static extern int GetFileAttributes(string lpFileName);
private static string EnsureLongPathPrefix(string path)
{
if (!path.StartsWith(@"\\?\", StringComparison.Ordinal))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we skip adding the prefix when the path is short?

Always adding the prefix will create a lot of garbage I think.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@lzybkr
Jason Shirk (lzybkr) merged commit ce4c35b into PowerShell:master Jun 8, 2017
@jeffbi
jeffbi deleted the item-exists-3891 branch June 8, 2017 00:26
@SteveL-MSFT Steve Lee (SteveL-MSFT) added the Backport-5.1-Consider Consider to backport to Windows PowerShell 5.1 due to impact label Mar 19, 2018
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
When calling Windows native API to determine if an item exists,
ensure the path is prepended with "\\?\" when the path is a long path.

Fixes PowerShell#3891
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Backport-5.1-Consider Consider to backport to Windows PowerShell 5.1 due to impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants