我有一个文本文件,其中包含文件列表及其完整路径以及扩展名,我想要的是将此文件列表复制到另一个文本文件,只包含文件名和扩展名,而不是整个路径。
例如 - 将demo.txt内容复制到test.txt
Demo.txt
C:\Demo\Excluded Files\AppData\List\ConfigurationUtility.BackUp.exe.config
C:\Demo\Excluded Files\AppData\List\ConfigurationUtility.exe.Config
C:\Demo\Excluded Files\AppData\List\ConfigurationUtility.WMIExtensions.XML
C:\Demo\Excluded Files\AppData\List\Microsoft.Administration.dll
C:\Demo\Excluded Files\AppData\List\ModelConfiguration.xml
C:\Demo\Excluded Files\AppData\List\Newtons.Json.dll
C:\Demo\Excluded Files\AppData\List\Data\Help\List User Guide.pdf
C:\Demo\Excluded Files\AppData\List\Data\Help\ListHelp.chm
C:\Demo\Excluded Files\AppData\List\Data\Help\intel Load Balancing.pdf
test.txt
ConfigurationUtility.BackUp.exe.config
ConfigurationUtility.exe.Config
ConfigurationUtility.WMIExtensions.XML
Microsoft.Administration.dll
ModelConfiguration.xml
Newtons.Json.dll
List User Guide.pdf
ListHelp.chm
intell Load Balancing.pdf
我如何使用PowerShell执行此操作?
答案 0 :(得分:2)
Get-Content demo.txt | %{Split-Path $_ -leaf} | Set-Content test.txt
要回答你从一开始就没有问过的另一个问题(因为我已经在狗窝里为不首先尝试的海报提供代码):
Get-Content demo.txt | %{(Split-Path $_ -leaf).Split('.')[-1]} | Set-Content test.txt