如何在PowerShell中复制只读和隐藏文件/文件夹?
要将只读项目和隐藏项目从一个位置复制到另一位置,需要将–Force参数与Copy-Itemcmdlet一起使用。
当您为只读/隐藏文件运行不带Force参数的命令时,会出现错误。下面给出一个例子。
示例
Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\
输出结果
PS C:\WINDOWS\system32> Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ Copy-Item : Access to the path 'D:\TempContent\Readonlyfile.txt' is denied. At line:1 char:1 + Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : PermissionDenied: (D:\Temp\Readonlyfile.txt:FileInfo) [Copy-Item], UnauthorizedAccessException + FullyQualifiedErrorId : CopyFileInfoItemUnauthorizedAccessError,Microsoft.PowerShell.Commands.CopyItemCommand
在cmdlet中添加–Force参数时,它也可以复制只读/隐藏文件。
示例
以下是只读文件的示例。
Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ -Force -PassThru
输出结果
PS C:\WINDOWS\system32> Copy-Item D:\Temp\Readonlyfile.txt -Destination D:\TempContent\ -Force -PassThru
Directory: D:\TempContent
Mode LastWriteTime Length Name
---- ------------- ------ ----
-ar--- 13-01-2020 18:19 0 Readonlyfile.txt示例
下面的示例适用于隐藏文件。
Copy-Item D:\Temp\hiddenfile.xlsx -Destination D:\TempContent\ -Force -PassThru
输出结果
PS C:\WINDOWS\system32> Copy-Item D:\Temp\hiddenfile.xlsx -Destination D:\TempContent\ -Force -PassThru
Directory: D:\TempContent
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a-h-- 13-12-2019 09:52 6182 hiddenfile.xlsx热门推荐
10 女神节日简短祝福语大全
11 朋友花篮开业祝福语简短
12 空军大学开学祝福语简短
13 宝宝新生入学祝福语简短
14 英文祝福语简短带名字
15 周年庆典祝福语致辞简短
16 最搞笑生日祝福语简短
17 老哥出门祝福语简短语
18 端午发给客户祝福语简短