如何在PowerShell中复制具有特定扩展名的文件?
要复制具有特定扩展名的文件,您需要使用Get-ChildItem命令。通过Get-ChildItem,您首先需要检索具有特定扩展名的文件,然后需要管道传递Copy-Item命令。
在这里,我们需要将*.txt文件从源复制到目标位置。
首先,我们将检索源路径中所有可用的*.txt文件。
示例
Get-ChildItem D:\Temp\ -Filter *.txt
输出结果
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Filter *.txt
Directory: D:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 26-01-2020 19:20 13818 aliases.txt
-a---- 18-01-2020 18:25 48 delim.txt
-a---- 18-01-2020 17:25 14 GetContentExample.txt
-a---- 17-01-2020 22:04 55190 Processes.txt
-a---- 18-01-2020 18:22 27620 ReadC.txt
-ar--- 13-01-2020 18:19 0 Readonlyfile.txt
-a---- 18-01-2020 18:44 22 stream1.txt
-a---- 18-01-2020 16:26 27620 testreadC.txt我们将上述文件复制到目标文件夹。
示例
Get-ChildItem D:\Temp\ -Filter *.txt | Copy-Item - Destination D:\TempContent\ -Force -PassThru
输出结果
PS C:\WINDOWS\system32> Get-ChildItem D:\Temp\ -Filter *.txt | Copy-Item -Destination D:\TempContent\ -Force -PassThru
Directory: D:\TempContent
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 26-01-2020 19:20 13818 aliases.txt
-a---- 18-01-2020 18:25 48 delim.txt
-a---- 18-01-2020 17:25 14 GetContentExample.txt
-a---- 17-01-2020 22:04 55190 Processes.txt
-a---- 18-01-2020 18:22 27620 ReadC.txt
-ar--- 13-01-2020 18:19 0 Readonlyfile.txt
-a---- 18-01-2020 18:44 22 stream1.txt
-a---- 18-01-2020 16:26 27620 testreadC.txt热门推荐
10 读书祝福语女生短句简短
11 感谢同事新婚祝福语简短
12 感谢教官文案祝福语简短
13 员工聚会蛋糕祝福语简短
14 元宵发客户祝福语简短
15 给团队信心祝福语简短
16 医美的祝福语大全简短
17 异国姻缘的祝福语简短
18 兄妹拍照祝福语简短的话