Skip to content

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

Merged
Mike Richmond (mirichmo) merged 3 commits into
PowerShell:masterfrom
jeffbi:rename-item-2799
May 3, 2017
Merged

Fix Rename-Item to allow Unix globbing patterns inpaths (#2799)#3661
Mike Richmond (mirichmo) merged 3 commits into
PowerShell:masterfrom
jeffbi:rename-item-2799

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 Ilya (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

Ilya (@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

Ilya (@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 Steve Lee (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
Mike Richmond (mirichmo) merged commit 2a739af into PowerShell:master May 3, 2017
@jeffbi
jeffbi deleted the rename-item-2799 branch May 8, 2017 04:57
Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj/PowerShell that referenced this pull request Aug 6, 2026
…2799) (PowerShell#3661)

* Fix Rename-Item to allow Unix globbing patterns in -Literal paths (PowerShell#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.

* Fix for AppVeyor failure

* Changes per code review, and a couple of letter-casing changes.
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