用于复制具有更改名称的文件的批处理脚本

时间:2021-12-03 16:25:15

Our build produces an archive with the name app-component-x.x.x.x-SNAPSHOT.zip where x.x.x.x is a version number (ie: 1.6.2.8). Directory is c:\buildresults\app

我们的构建生成一个名为app-component-x.x.x.x-SNAPSHOT.zip的存档,其中x.x.x.x是版本号(即:1.6.2.8)。目录是c:\ buildresults \ app

We want to write a batch script that a) copies the file to another directory with a fixed name such as build-results.zip and then b) extracts the file.

我们想编写一个批处理脚本,a)将文件复制到另一个具有固定名称的目录,例如build-results.zip,然后b)提取文件。

I am not sure how to do part A. This doesn't seem to work: copy c:\buildresults\app\*.zip c:\xxx\build-results.zip

我不知道如何做A部分。这似乎不起作用:复制c:\ buildresults \ app \ * .zip c:\ xxx \ build-results.zip

Any ideas?


Update:

File is being copied BUT the size is dramatically less. Ie: the file seems to be getting corrupted.

正在复制文件但是大小要小得多。即:文件似乎已损坏。

This seems to work but not ideal:

这似乎有效但不理想:

cd buildresults\app

for %%f in (*component*) do (
    echo %%~nf
    7za.exe -oC:\buildresults\app x "%%~nf.zip"
)

2 个解决方案

#1


0  

You could try:

你可以尝试:

xcopy /Y /Q /C /H /R c:\buildresults\app\*.zip c:\xxx\build-results.zip

#2


0  

Cannot reproduce:

D:\>mkdir xxx

D:\>echo test > test-1.2.3.zip

D:\>copy test-*.zip xxx\test-current.zip
test-1.2.3.zip
        1 Datei(en) kopiert.

D:\>type xxx\test-current.zip
test

D:\>

Are you sure the target doesn't exist? Btw, are you sure your * matches exactly one file in every case? Because copying multiple files to one destination is a valid operation and will end up with an invalid zip file.

你确定目标不存在吗?顺便说一下,你确定你的*在每种情况下只匹配一个文件吗?因为将多个文件复制到一个目标是一个有效的操作,最终会得到一个无效的zip文件。

#1


0  

You could try:

你可以尝试:

xcopy /Y /Q /C /H /R c:\buildresults\app\*.zip c:\xxx\build-results.zip

#2


0  

Cannot reproduce:

D:\>mkdir xxx

D:\>echo test > test-1.2.3.zip

D:\>copy test-*.zip xxx\test-current.zip
test-1.2.3.zip
        1 Datei(en) kopiert.

D:\>type xxx\test-current.zip
test

D:\>

Are you sure the target doesn't exist? Btw, are you sure your * matches exactly one file in every case? Because copying multiple files to one destination is a valid operation and will end up with an invalid zip file.

你确定目标不存在吗?顺便说一下,你确定你的*在每种情况下只匹配一个文件吗?因为将多个文件复制到一个目标是一个有效的操作,最终会得到一个无效的zip文件。