Skip to content

Conversation

@jeffbi
Copy link
Contributor

@jeffbi jeffbi commented Apr 28, 2017

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.
Copy link
Collaborator

@iSazonov iSazonov left a comment

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
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
Contributor 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
Collaborator

@jeffbi

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

What about New-Item?

@jeffbi
Copy link
Contributor Author

jeffbi commented Apr 28, 2017

@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
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
Copy link
Contributor Author

jeffbi commented Apr 28, 2017

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

@iSazonov
Copy link
Collaborator

@jeffbi Many thanks!

LGTM.

Copy link
Member

@SteveL-MSFT SteveL-MSFT left a comment

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