我有一个带有.exe examle (hello/my-file-print-on-text-2.0.1-win-x64.exe)的文件,该文件的版本为2.0.1,之后的版本将更改为2.0.2。等等。
每当使用cp命令自动更新版本时,我想将这个相同的文件复制到不同的文件夹中。
我可以帮助如何使此文件名与通配符
我尝试了下面的方法,但它不起作用,这是在windows机器上,而不是linux。
cp "hello/my-file-print-on-text-*-win-x64.exe)" "hello/my-file-print-on-text.exe)"
cp "hello/my-file-print-on-text*-win-x64.exe)" "hello/my-file-print-on-text.exe)"如何使用带有通配符的cp命令当文件的版本发生变化时,应使用新名称进行复制?
发布于 2021-11-24 13:27:20
好的,您说您是在Windows中执行此操作,因此我将提供一个使用Powershell来实现您所需的解决方案(将单个可执行文件复制到一个名为的文件夹中,该文件夹的版本号来自)。这可以与Azure Pipeline中的powershell或pwsh任务类型一起使用:
# Find the EXE to copy, get the first result
$exeFile = (Get-ChildItem hello/my-file-print-on-text-*-win-x64.exe |
Select-Object -First 1 Name).Name
# if the name of the file has some form of version in the name,
if ($exeFile -match "my-file-print-on-text-(.*)-win-x64.exe") {
# grab the version
$version = $Matches[1]
# change this to the structure of the folder name you want
$targetFolder = "path-containing-$version-number"
# verify or create the target folder
if (!(Test-Path $targetFolder)) {
New-Item -ItemType Directory $targetFolder
}
# and then copy the EXE there
Copy-Item $n $targetFolder
}https://stackoverflow.com/questions/70095669
复制相似问题