- Notifications
You must be signed in to change notification settings - Fork8.1k
Fix Move-Item with wildcard to non-existent destination flattening first directory#26604
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:master
Are you sure you want to change the base?
Changes fromall commits
10ba69413cfcaebd477712c8a38cc038b6e59e273c98a08c25369559e38c682a3b381ee9881be77f08179b18849758bc57File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -2984,21 +2984,49 @@ private Collection<PathInfo> GetResolvedPaths(string path) | ||
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| // When moving multiple items with wildcards to a non-existent destination, | ||
| // we need to create the destination directory first to ensure all items | ||
| // preserve their directory structure. Otherwise, the first directory gets | ||
| // renamed to the destination, and subsequent items are moved into it. | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @copilot Please remove the extra line. | ||
| if (!base.SuppressWildcardExpansion) | ||
| { | ||
| // First, collect all resolved paths to determine if we're moving multiple items | ||
| var allResolvedPaths = new List<string>(); | ||
| foreach (string path in Path) | ||
| { | ||
| Collection<PathInfo> resolvedPaths = GetResolvedPaths(path); | ||
| foreach (PathInfo resolvedPathInfo in resolvedPaths) | ||
| { | ||
| allResolvedPaths.Add(resolvedPathInfo.Path); | ||
| } | ||
| } | ||
| // If moving multiple items and destination doesn't exist, create it first | ||
| if (allResolvedPaths.Count > 1 && !InvokeProvider.Item.Exists(Destination)) | ||
| { | ||
| try | ||
| { | ||
| InvokeProvider.Item.New(Destination, null, "Directory", null, CmdletProviderContext); | ||
Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @copilot Please use named arguments for null-s. Collaborator There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others.Learn more. @copilot Please address my request. | ||
| } | ||
| catch (Exception) | ||
| { | ||
| // If creation fails, continue anyway - the move operation will handle the error | ||
| } | ||
| } | ||
| // Now proceed with the moves | ||
| foreach (string resolvedPath in allResolvedPaths) | ||
| { | ||
| MoveItem(resolvedPath, literalPath: true); | ||
| } | ||
| } | ||
| else | ||
| { | ||
| // Literal path mode - process each path directly | ||
| foreach (string path in Path) | ||
| { | ||
| MoveItem(path, literalPath: true); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading.Please reload this page.