Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix Rename-Item to allow Unix globbing patterns inpaths (#2799)#3661

Merged
mirichmo merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
jeffbi:rename-item-2799Copy head branch name to clipboard
May 3, 2017
Merged

Fix Rename-Item to allow Unix globbing patterns inpaths (#2799)#3661
mirichmo merged 3 commits into
PowerShell:masterPowerShell/PowerShell:masterfrom
jeffbi:rename-item-2799Copy head branch name to clipboard

Conversation

@jeffbi

@jeffbi jeffbi commented Apr 28, 2017

Copy link
Copy Markdown

Fixes #2799

In the process of normalizing a relative path, PowerShell checks to see
see if the path exists, which it does by invoking Directory.EnumerateFiles(directory, filename);

On Unix platforms, if the filename contains globbing patterns, such as [ab],
EnumerateFiles (and EnumerateDirectories) will perform the globbing. Using
globbing patterns, a file named file[txt].txt is reported as not existing.

This fix changes the file-existence test on Unix to use a native function
instead of either of the Directory.EnumerateXXX functions.

This affects the Move-Item, Remove-Item, Rename-Item and Copy-Item cmdlets. This change does not affect the New-Item cmdlet, as it is able to create files with names containing Unix globbing characters.

)

In the process of normalizing a relative path, PowerShell checks to see
see if the path exists, which it does by invoking
    Directory.EnumerateFiles(directory, filename);

On Unix platforms, if the filename contains globbing patterns, such as [ab],
EnumerateFiles (and EnumerateDirectories) will perform the globbing. Using
globbing patterns, a file named 'file[txt].txt' is reported as not existing.

This fix changes the file-existence test on Unix to use a native function
instead of either of the Directory.EnumerateXXX functions.

@iSazonov iSazonov left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@jeffbi Original Issue say *-Item but the PR fix only Rename-Item. Please add comment about this in the PR description.

$dirPath = Join-Path $TESTDRIVE "subdir"
}
BeforeEach {
$file = New-Item -ItemType File $filePath -Force

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Please add -Path in all places wherever flowed.

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.

@iSazonov

Copy link
Copy Markdown
Collaborator

@jeffbi

This affects the Move-Item, Remove-Item, Rename-Item and Copy-Item cmdlets.

What about New-Item?

@jeffbi

jeffbi commented Apr 28, 2017

Copy link
Copy Markdown
Author

@iSazonov The issue didn't affect New-Item. New-Item was able to create the file file[txt].txt, it was the other cmdlets that couldn't find the file once it was created.

@iSazonov

Copy link
Copy Markdown
Collaborator

@jeffbi My question was again about addition to the PR description. I expect that this will help make PowerShell documentation more precise. Thanks!

@jeffbi

jeffbi commented Apr 28, 2017

Copy link
Copy Markdown
Author

@iSazonov OK, I've updated the PR description to include a note about New-Item

@iSazonov

Copy link
Copy Markdown
Collaborator

@jeffbi Many thanks!

LGTM.

@SteveL-MSFT SteveL-MSFT left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@mirichmo mirichmo merged commit 2a739af into PowerShell:master May 3, 2017
@jeffbi jeffbi deleted the rename-item-2799 branch May 8, 2017 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

*-Item should handle files with wildcard characters

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.