Fixes #12621 - Document behavior of wildcard matching when -Destination doesn't exist#12670
Conversation
PoliCheck Scan ReportThe following report lists PoliCheck issues in PR files. Before you merge the PR, you must fix all severity-1 and severity-2 issues. The AI Review Details column lists suggestions for either removing or replacing the terms. If you find a false positive result, mention it in a PR comment and include this text: #policheck-false-positive. This feedback helps reduce false positives in future scans. ✅ No issues foundMore information about PoliCheckInformation: PoliCheck | Severity Guidance | Term |
There was a problem hiding this comment.
Pull request overview
This pull request documents the behavior of Copy-Item when using wildcard matching with a non-existent destination path, addressing issue #12621. The changes include documentation updates and code example improvements across multiple PowerShell versions.
Changes:
- Added documentation explaining the behavior when the destination doesn't exist with wildcard paths
- Refactored several code examples to use PowerShell splatting pattern for better readability
- Updated the ms.date metadata field to reflect the documentation update
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 12 comments.
| File | Description |
|---|---|
| reference/7.6/Microsoft.PowerShell.Management/Copy-Item.md | Added wildcard behavior documentation, refactored Examples 4, 8, and 11 to use splatting, updated date metadata |
| reference/7.5/Microsoft.PowerShell.Management/Copy-Item.md | Added wildcard behavior documentation note only, updated date metadata |
| reference/7.4/Microsoft.PowerShell.Management/Copy-Item.md | Added wildcard behavior documentation, refactored Examples 4, 8, and 11 to use splatting, updated date metadata |
| reference/5.1/Microsoft.PowerShell.Management/Copy-Item.md | Added wildcard behavior documentation, refactored Examples 4, 8, and 11 to use splatting, updated date metadata |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| > | ||
| > `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse` | ||
| > | ||
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
There was a problem hiding this comment.
Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
| > | ||
| > `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse` | ||
| > | ||
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
There was a problem hiding this comment.
Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | ||
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | ||
| > file is a copy of the last file in the `C:\Logfiles` directory. |
There was a problem hiding this comment.
The documentation states "all files in C:\Logfiles are copied to C:\Drawings\Logs as a file" which is confusing and unclear. The phrase "copied to C:\Drawings\Logs as a file" doesn't make sense because multiple files cannot be copied to a single file path. The statement should clarify that each file except the last is overwritten by the next, resulting in only the last file being preserved, or describe the actual behavior more accurately.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | |
| > file is a copy of the last file in the `C:\Logfiles` directory. | |
| > If `C:\Logfiles` contains only files (no subdirectories) and `C:\Drawings\Logs` doesn't exist, | |
| > each file in `C:\Logfiles` is copied in turn to the same destination path, `C:\Drawings\Logs`, | |
| > so each copy overwrites the previous one. The resulting `C:\Drawings\Logs` file is a copy of | |
| > the last file in the `C:\Logfiles` directory. |
| > | ||
| > `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse` | ||
| > | ||
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
There was a problem hiding this comment.
Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
| > | ||
| > `Copy-Item -Path "C:\Logfiles\*" -Destination "C:\Drawings\Logs" -Recurse` | ||
| > | ||
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
There was a problem hiding this comment.
Grammar error: "If the C:\Logfiles only contains" should be "If C:\Logfiles only contains" (remove "the" before the path). Paths used as subjects don't require the article "the" in this context.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't |
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | ||
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | ||
| > file is a copy of the last file in the `C:\Logfiles` directory. | ||
|
|
There was a problem hiding this comment.
The documentation states "all files in C:\Logfiles are copied to C:\Drawings\Logs as a file" which is confusing and unclear. The phrase "copied to C:\Drawings\Logs as a file" doesn't make sense because multiple files cannot be copied to a single file path. The statement should clarify that each file except the last is overwritten by the next, resulting in only the last file being preserved, or describe the actual behavior more accurately.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | |
| > file is a copy of the last file in the `C:\Logfiles` directory. | |
| > If `C:\Logfiles` contains only files and no subdirectories, and `C:\Drawings\Logs` doesn't | |
| > exist, PowerShell treats `C:\Drawings\Logs` as a file path rather than a directory. Each file in | |
| > `C:\Logfiles` is copied in turn to `C:\Drawings\Logs`, overwriting the previous one, so the final | |
| > `C:\Drawings\Logs` file is a copy of the last file in the `C:\Logfiles` directory. |
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | ||
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | ||
| > file is a copy of the last file in the `C:\Logfiles` directory. | ||
|
|
There was a problem hiding this comment.
Inconsistent reference: The sentence refers to "The C:\Drawings file" but previously mentions "C:\Drawings\Logs" as the destination. This creates confusion because C:\Drawings is described as a file rather than a directory. The sentence should clarify that when C:\Drawings\Logs doesn't exist, it's treated as a file path (not a directory), and explain the behavior more clearly.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | |
| > file is a copy of the last file in the `C:\Logfiles` directory. | |
| > If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, the destination path is treated as a file name rather than a directory. A single file | |
| > named `C:\Drawings\Logs` is created, and its contents are a copy of the last file in the | |
| > `C:\Logfiles` directory that is processed. |
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | ||
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` |
There was a problem hiding this comment.
The documentation states "all files in C:\Logfiles are copied to C:\Drawings\Logs as a file" which is confusing and unclear. The phrase "copied to C:\Drawings\Logs as a file" doesn't make sense because multiple files cannot be copied to a single file path. The statement should clarify that each file except the last is overwritten by the next, resulting in only the last file being preserved, or describe the actual behavior more accurately.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | |
| > If `C:\Logfiles` contains only files (no subdirectories) and `C:\Drawings\Logs` doesn't | |
| > exist, PowerShell treats `C:\Drawings\Logs` as the path to a single file. Each file from | |
| > `C:\Logfiles` is copied to that same destination path in turn, so the final `C:\Drawings\Logs` |
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | ||
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | ||
| > file is a copy of the last file in the `C:\Logfiles` directory. | ||
|
|
There was a problem hiding this comment.
Inconsistent reference: The sentence refers to "The C:\Drawings file" but previously mentions "C:\Drawings\Logs" as the destination. This creates confusion because C:\Drawings is described as a file rather than a directory. The sentence should clarify that when C:\Drawings\Logs doesn't exist, it's treated as a file path (not a directory), and explain the behavior more clearly.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | |
| > file is a copy of the last file in the `C:\Logfiles` directory. | |
| > If `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, `Copy-Item` treats `C:\Drawings\Logs` as a file path, not a directory. Each file from | |
| > `C:\Logfiles` is copied in turn to `C:\Drawings\Logs`, so the `C:\Drawings\Logs` file ends up | |
| > containing the contents of the last file in the `C:\Logfiles` directory. |
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | ||
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | ||
| > file is a copy of the last file in the `C:\Logfiles` directory. |
There was a problem hiding this comment.
Inconsistent reference: The sentence refers to "The C:\Drawings file" but previously mentions "C:\Drawings\Logs" as the destination. This creates confusion because C:\Drawings is described as a file rather than a directory. The sentence should clarify that when C:\Drawings\Logs doesn't exist, it's treated as a file path (not a directory), and explain the behavior more clearly.
| > If the `C:\Logfiles` only contains files and no subdirectories and `C:\Drawings\Logs` doesn't | |
| > exist, all files in `C:\Logfiles` are copied to `C:\Drawings\Logs` as a file. The `C:\Drawings` | |
| > file is a copy of the last file in the `C:\Logfiles` directory. | |
| > If `C:\Logfiles` contains only files and no subdirectories and `C:\Drawings\Logs` doesn't exist, | |
| > `Copy-Item` treats `C:\Drawings\Logs` as the full path to a file, not a directory. All files in | |
| > `C:\Logfiles` are copied in sequence, and the contents of the last file overwrite the previous | |
| > content. The resulting `C:\Drawings\Logs` file contains the contents of the last file in the | |
| > `C:\Logfiles` directory. |
|
Learn Build status updates of commit c62c1d3: ✅ Validation status: passed
For more details, please refer to the build report. |
PR Summary
Document behavior of wildcard matching when -Destination doesn't exist
Copy-Item's behavior when wildcard matching is performed and-Destinationdoesn't exist #12621PR Checklist