-
Notifications
You must be signed in to change notification settings - Fork 7.1k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Copy-Item puts contents of 1st directory in root of target folder. #7005
Comments
Other (hopefully) useful info:
|
The SO answer you link to links back to #2934, but the latter is about inconsistent behavior, because the behavior depends on whether the target directory already exists or not. The question comes down to this: If you do Copy-Item -Recurse <source-dir-path> <dest-dir-path> should you end up with (a) Currently, you get (a) if It sounds like you're saying that (b) is the behavior you expect - and at this point I'm unclear on what the right answer is:
|
My mistake on the SO link, you're correct that isn't relevant to this bug report. I've removed it from the second comment. My problem is: assuming You should be able to see a "graphical" representation of what I described in the example at the top as well I think. I expect |
Yes, but that is the same problem as #2934, just in the context of a larger command:
Therefore, if you run the command again, you do get the desired behavior. Given the current behavior, you can work around the problem as follows: Get-ChildItem -Path $a |
ForEach-Object { New-Item -Force -Type Directory $b } {
Copy-Item -Recurse -Path $_.FullName -Destination $b
} But the larger question is whether this inconsistency should be resolved toward behavior (a) or behavior (b). You clearly expected (a), but others may have different expectations, based on Frankly, I was baffled to find the same inconsistency as with The only way to currently get predictable behavior is to:
If a change is made, it will be a breaking one. The alternative is to merely document the behavior and live with it, but I personally find that unsatisfactory. Unless you disagree with my analysis, I suggest closing this issue as a duplicate of #2934; I'll migrate my findings there. |
I experimented a little and found that "Unix" (I'm using cygwin) Example: $ pwd
~/tmp
# Contents
# a
# a\boo
# a\boo\c.d
# a\doom.txt
# a\foo
# a\foo\a.b
# z is a directory and doesn't exist yet.
cp -R a z
# contents of z
# z
# z\boo
# z\boo\c.d
# z\doom
# z\foo
# z\foo\a.b
If another In this scenario, you'll see that although the directory did not exist before the copy, the contents of |
@huffstler: Good point; yes, there is an additional bug, which I've only a couple of hours ago recorded in #7010 - and which I now realize is a variation of yours. |
I encounter the same problem when I want to copy the subfolder structure of a source folder to an existing target folder |
Well, in UNIX world you can always do |
Unfortunately, it's too late to introduce such semantics to PowerShell, because it would be a breaking change. Aside from that: While
|
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
2 similar comments
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has not had any activity in 6 months, if this is a bug please try to reproduce on the latest version of PowerShell and reopen a new issue and reference this issue if this is still a blocker for you. |
This issue has been marked as "No Activity" as there has been no activity for 6 months. It has been closed for housekeeping purposes. |
Steps to reproduce
Expected behavior
Actual behavior
Environment data
The text was updated successfully, but these errors were encountered: