我需要一个批处理文件来检查文件是否存在于最近一次修改日期为特定文件夹的当前月份&年。批处理文件检查当前月份创建的文件是否存在
例如:本月显示FEB-16 (02/2016);
(日期并不重要,我)
文件夹/文件名我可以输入,因为它是静态的。
我需要一个批处理文件来检查文件是否存在于最近一次修改日期为特定文件夹的当前月份&年。批处理文件检查当前月份创建的文件是否存在
例如:本月显示FEB-16 (02/2016);
(日期并不重要,我)
文件夹/文件名我可以输入,因为它是静态的。
您可以使用此:
@echo off
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%"
set /p "file=Enter your file here: "
if not exist "%file%" (
echo file %file% not found
goto end
)
FOR %%i IN ("%file%") DO (
for /f "tokens=2,3 delims=-: " %%g in ("%%~ti") do (
if "%%h%%g"=="%YYYY%%MM%" (
echo %%i is from this month!
)
if not "%%h%%g"=="%YYYY%%MM%" (
echo %%i is not from this month!
)
)
)
:end
pause
编辑
区域设置非特定版本:
@echo off
setlocal EnableDelayedExpansion
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%"
set /p "file=Enter your file here: "
if not exist "%file%" (
echo file %file% not found
goto end
)
FOR %%i IN ("%file%") DO (
set "escapedFile=%%~dpnxi"
set "escapedFile=!escapedFile:\=\\!"
for /f "tokens=2 delims==" %%a in ('wmic datafile where name^="!escapedFile!" get LastModified /value') do set "dt2=%%a"
set "YYYY2=!dt2:~0,4!" & set "MM2=!dt2:~4,2!"
if "!YYYY2!-!MM2!"=="!YYYY!-!MM!" (
echo %%i is from this month!
)
if not "!YYYY2!-!MM2!"=="!YYYY!-!MM!" (
echo %%i is not from this month!
)
)
:end
pause
感谢您的回复。是否可以为以下情况添加消息: –
1.如果在该路径中没有文件 –
2.如果文件存在但它不符合日期标准 –
我提高了可读性一点点。然而,你有尝试过目前为止?如果您显示一些代码,则更容易获得答案。 – Alexei