我为一个Jenkins作业编写了一个批处理脚本,它编译了一个".net“代码,其中一个步骤是在提取新编译的代码之前备份当前目录。
我使用这些行提取要插入备份文件名的日期和时间:
for /F "tokens=2-4 delims=/ " %%i in ('date /t') do set date=%%k%%i%%j
for /f "tokens=1-2 delims=/:" %%a in ('time /t') do set time=%%a%%b
powershell.exe -nologo -noprofile -command "& { Add-Type -A System.IO.Compression.FileSystem; [IO.Compression.ZipFile]::CreateFromDirectory('bin', 'bin-%date%_%time%.zip'); }"
xcopy bin-%date%_%time%.zip c:\temp问题在于time /t的输出,它看起来如下:
01:00 AM这将导致文件名为:
bin-20170412-0100 AM.zip这是个问题。
我想省略时间变量中的“AM”,怎么做呢?
发布于 2017-04-12 09:06:15
由于显然您对powershell的使用没有问题,所以将前两行替换为:
For /F %%A In ('Powershell -C "Get-Date -Format yyyyMMdd_HHmm"'
) Do Set "archive=bin-%%A.zip"然后,在变量%archive%中设置完整的存档文件名,以便在以下命令中使用。
https://stackoverflow.com/questions/43363804
复制相似问题