question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Copy-Item does not retain Hidden attribute

See original GitHub issue

Copied items do not retain their attributes.

Steps to reproduce

md temp1
md temp2
cd .\temp1\
git init
(Get-Item .\.git\ -Force).Attributes
# Output:  Hidden, Directory
Copy-Item * ..\temp2\ -Recurse -Force
cd ..\temp2\
(Get-Item .\.git\ -Force).Attributes
# Output:  Directory

Expected behavior

The .git folder should still have the Hidden attribute after it is copied.

Actual behavior

The .git folder no longer has the Hidden attribute.

Environment data

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.18362
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
iSazonovcommented, Oct 1, 2020

It is not clear - today we copy only file attributes:

  • will preserve current behavior without these new parameters?
  • with IncludeAttributes will we copy both file and directory attributes?
  • with ExcludeAttributes will we exclude all file and directory attributes?

It seems we get a complex behavior and it can confuse users. I’d prefer more simple UX.

Since file attributes are coped by default should new parameter be -IncludeDirectoryAttributes? And what about with Exclude in the case? Have -ExcludeFileAttributes only or -ExcludeDirectoryAttributes too?


I tested with Far Manager - it copies directory attributes by default. If this feature is present and gone then it will definitely be a bucket 3 breaking change. But if this feature is not present, and it will be added, then this is definitely not a breaking change. (Those to whom it is important use a workaround today. Those who don’t care ignore it at all.)

My proposal is:

  • add the feature (copy directory attributes) by default (as experimental feature)
  • add backward compatibility switch ExcludeDirectoryAttributes

We have about 1 year for getting feedbacks and adoption.

0reactions
SteveL-MSFTcommented, Dec 16, 2020

@PowerShell/powershell-committee reviewed this again, we agree on an experimental feature that copies the directory attributes. In addition, not having any -ExcludeDirectoryAttributes switch initially unless customer feedback makes it clear this is needed. In the case of someone copying a ReadOnly directory and subsequently trying to write to it because it worked previously they would get a clear error message and should update their script to modify the directory attribute explicitly.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Powershell Copy-Item -force doesn't preserve invisible ...
Is there a simple method to copy hidden folders as they are or do I need to iterate over each copied item and...
Read more >
Should copy-item perhaps preserve attribute hidden for ...
I'm currently working with DISM in WinPE... There's no PS equivalent cmdlet for ROBOCOPY or XCOPY. ROBOCOPY /COPY:DATSO /E ROBOCOPY /DCOPY:DAT / ...
Read more >
Copy-Item (Microsoft.PowerShell.Management)
The Copy-Item cmdlet copies an item from one location to another location in the same namespace. ... This cmdlet doesn't cut or delete...
Read more >
PowerShell Copy Item examples
We can use Copy-Item to copy an item from one location to another. The command only copies the item, it will not cut...
Read more >
Hide-When attributes do not correspond to field level ...
When you bring the information to the destination field, you notice that hide-when attributes are enabled that do not correspond to the field...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found