如何压缩文件名中包含今天日期的文件夹? [英] How to zip folders containing today's date in the filename?

查看:216
本文介绍了如何压缩文件名中包含今天日期的文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个批处理文件和一个vbs文件,用于压缩具有特定目录名称的文件夹并将其复制到另一个文件夹.

I have a batch and a vbs file to zip a folder with a specific directory name and copy it to another folder.

我怎么只压缩包含今天日期的文件夹? 如果不可能,如何仅将具有今天日期的文件夹压缩为"Date Modified"(修改日期)列?

How could I zip only the folder containing today's date? If it is not possible how could I zip only the folder having today's date as "Date Modified" column?

蝙蝠:

@echo off
set "mypath=C:\TEMP\zip\source\JEAR_20190115"
for /f %%i in ('dir /b /a-d "%mypath%"') do set "last=%%~ni"
CScript zip.vbs %mypath% C:\TEMP\zip\target\%last%.zip

vbs:

'Get command-line arguments.
Set objArgs = WScript.Arguments
InputFolder = objArgs(0)
ZipFile = objArgs(1)

'Create empty ZIP file.
CreateObject("Scripting.FileSystemObject").CreateTextFile(ZipFile,         
True).Write "PK" & Chr(5) & Chr(6) & String(18, vbNullChar)

Set objShell = CreateObject("Shell.Application")

Set source = objShell.NameSpace(InputFolder).Items

objShell.NameSpace(ZipFile).CopyHere(source)

'Required!
wScript.Sleep 2000

例如,以下文件比今天更旧,因此不应压缩.

For example the following file is older than today so it shouldn't be zipped.

set "mypath=C:\TEMP\zip\source\JEAR_20190115"

如果等于今天,则脚本应运行:

If it would be equal to today's date the script should run:

set "mypath=C:\TEMP\zip\source\JEAR_20190117"

上一个问题: https://stackoverflow.com/a/54216776/7420833

推荐答案

其余的解释与前面的问题相同,但是我们只添加了一些vbs代码即可以所需的格式获取正确的日期.

The explanations remains the same for the rest, as per the previous question, but we simply add some vbs code to get the correct date in the required format.

@echo off
echo >"%temp%\%~n0.vbs" s=DateAdd("d",0,now) : d=weekday(s)
echo>>"%temp%\%~n0.vbs" WScript.Echo year(s)^& right(100+month(s),2)^& right(100+day(s),2)
for /f %%a in ('cscript /nologo "%temp%\%~n0.vbs"') do set "result=%%a"
if exist "C:\TEMP\zip\source\JEAR_%result%" (
    set "mypath=C:\TEMP\zip\source\JEAR_%result%"
 )  else (
    exit
 )
if "%mypath:~-1%"=="\" set "mypath=%mypath:~0,-1%"
for %%i in (%mypath%) do set "last=%%~nxi"
CScript zip.vbs %mypath% C:\TEMP\zip\target\%last%.zip

使用原因

这篇关于如何压缩文件名中包含今天日期的文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆