Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell 使用Get-ChildItem和copy-item将多个文件合并为一个文本文件_Powershell - Fatal编程技术网

Powershell 使用Get-ChildItem和copy-item将多个文件合并为一个文本文件

Powershell 使用Get-ChildItem和copy-item将多个文件合并为一个文本文件,powershell,Powershell,我正在尝试复制文件夹中最新的3个文件(按修改日期),然后将这3个文件复制/合并为1个文本文件 get-childitem *.* | sort LastWriteTime | select -last 3 | copy-item -destination last3files.txt 这就是我尝试过的。它查找最后3个文件,但在我使用管道复制项目时仅复制1个文件。。未将所有3个文本文件复制/合并为1个文本文件 get-childitem *.* | sort LastWriteTime |

我正在尝试复制文件夹中最新的3个文件(按修改日期),然后将这3个文件复制/合并为1个文本文件

 get-childitem *.* | sort LastWriteTime | select -last 3 | copy-item -destination last3files.txt
这就是我尝试过的。它查找最后3个文件,但在我使用管道复制项目时仅复制1个文件。。未将所有3个文本文件复制/合并为1个文本文件

 get-childitem *.* | sort LastWriteTime | select -last 3 | copy-item -destination last3files.txt
如果可能的话,我想要一艘班轮


谢谢

如果要合并文件内容,需要添加读取文件内容并设置文件内容的步骤<代码>获取内容|设置内容

Get-ChildItem *.* | Sort-Object LastWriteTime |
    Select-Object -Last 3 | Get-Content | Set-Content last3files.txt
Copy Item
将仅复制来自同一命名空间的项,而不复制这些项的文本内容


您可能需要签出并使用
-编码
选项,以防您的文件中混合了编码。

如果要合并文件内容,则需要添加读取文件内容并设置文件内容的步骤<代码>获取内容|设置内容。