gpt4 book ai didi

powershell - 通过PowerShell复制文件夹中的最新文件,并按名称的一部分排除文件

转载 作者:行者123 更新时间:2023-12-02 23:25:33 24 4
gpt4 key购买 nike

我尝试使用以下类型的命令从文件夹(.exe文件)复制最新文件:

Get-ChildItem "K:\" -File -include "*.exe" | Where-Object { $_. $_.LastWriteTime like "I don't know which parameter I should type here} Copy-Item -Path $files -Destination "C:\"

我不想将复杂的脚本与变量等一起使用(目前)

这是我拥有的文件夹结构:
  • Release_OSInstaller_2015_CL287638x64_NoDB.exe
  • Release_OSInstaller_2015_CL287638x64.exe
  • Release_OSInstaller_2015_CL287337x64_NoDB.exe
  • Release_OSInstaller_2015_CL287337x64.exe

  • 等等。基本上,每天都会在文件夹中部署新的构建版本,然后从该文件夹中将文件复制到我的计算机上(远程)。

    我需要创建一个脚本,该脚本将复制最新版本,但是我想排除所有带有“NoDB.exe”参数的文件。

    最佳答案

    除了answer from whatever之外,您还可以添加Where条件并跳过NoDB文件:

    Get-ChildItem "K:\" -Filter '*.exe' | 
    Where Name -NotMatch '.*NoDB\.exe$' |
    sort LastWriteTime -Descending |
    select -first 1 |
    Copy-Item -Destination 'C:\'

    关于powershell - 通过PowerShell复制文件夹中的最新文件,并按名称的一部分排除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37853047/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com