如何在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热门推荐
1 狗狗下楼训练
3 狗狗训练头盔
6 狗狗训练机构
7 训练狗狗步骤
9 狗狗能训练
10 狗狗基本动作训练方法
11 怎么训练狗狗叼饭盆
12 狗狗一岁了还能训练吗
13 训练狗狗的
14 宁波狗狗训练
15 训练狗狗拉屎
16 教狗狗训练
17 狗狗要怎么训练上厕所
18 狗狗靠的训练