有没有在今天的修改日期的目录文件

有没有在今天的修改日期的目录文件

本文介绍了有没有在今天的修改日期的目录文件 - 批处理文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的批处理文件,并有一些基本的了解,如果我看到他们在我面前可以编辑批次。
我不知道你能不能帮我为我的批处理文件下列要求。

 是否有在目录中的文件与当今的修改日期
如是
有文件中的测试的一个特定文本串
    如是
        回声测试字符串发现
    其他
        回声测试字符串找不到
其他
    回声没有文件今天


解决方案

  @ECHO OFF
SETLOCAL
::点到目标目录。建立所需的目标文件和字符串
设置目标=。
SET targfile = example.txt文件
SET targtxt =找我
::
SET targfile =%的目标%\\%targfile%
IF NOT EXIST%targfile%ECHO现今放任何文件; GOTO:EOF
:dfloop
SET文件名= Q%随机%.Q $ Q
SET全称=%的目标%\\%文件名%
如果存在的全称%GOTO%dfloop
::造就了今天日的虚拟文件
COPY NUL:%FULLNAME%GT; NUL
 FOR / F %% i的('DIR%全名%^ |找到/ I%文件名%)今天做套= %%我
DEL%FULLNAME%
FOR / F %% i的('DIR%targfile%')怎么做,如果今天%% == %%我(SET今天=)
如果定义今天现今放ECHO没有文件; GOTO:EOF
FIND / I%targtxt%%targfile%GT; NUL
IF ERRORLEVEL 1(ECHO测试字符串未找到)ELSE(ECHO测试字符串中)

我给自己定的目标目录为 - 当前目录 - 用于测试。替换与您的目标目录名。

中查找目标文件的字符串'example.txt的

现在 - 即假定你正在寻找可能出现的特定文件名/目录中被修改,如 ... \\ myappdir \\ myapp.log

如果你的意思是任意文件[匹配一些文件掩码]已创建/修改的今天是要搜索的字符串,然后稍微修改程序:

  @ECHO OFF
SETLOCAL
::点到目标目录。建立需要的目标文件匹配和字符串
设置目标= \\ DESTDIR
SET targfile = examp * .TXT
SET targtxt =找我
::
SET targfile =%的目标%\\%targfile%
IF NOT EXIST%targfile%ECHO现今放任何文件; GOTO:EOF
:dfloop
SET文件名= Q%随机%.Q $ Q
SET全称=%的目标%\\%文件名%
如果存在的全称%GOTO%dfloop
::造就了今天日的虚拟文件
COPY NUL:%FULLNAME%GT; NUL
FOR / F %% i的('DIR%全名%^ |找到/ I%文件名%)今天做套= %%我
DEL%FULLNAME%
SET计数= 0
FOR / F %% i的('DIR%targfile%')怎么做,如果今天%% == %%我(SET /计数+ = 1)
IF%计%EQU 0 ECHO没有文件今天和放大器; GOTO:EOF
FOR / F= 1 * delims =令牌:我%% IN(
 DIR / B / A-D / O-D%targfile%^ | FINDSTR / N / V*'
  )怎么做,如果我%%当量%计数%(
FIND / I%targtxt%%的目标%\\ %% J> NUL
IF NOT ERRORLEVEL 1(SET今天=)

如果今天DEFINED(ECHO测试字符串未找到)ELSE(ECHO测试字符串中)

在这里,任何文件匹配 examp * .TXT 已创建/今日 \\ DESTDIR 修改将是检查目标字符串。

I am new to batch files and have some basic understanding and can edit batches if I see them in front of me.I wonder if you could help me with the following requirement for my batch file.

Is there a file in a directory with a modified date of today
If yes
Is there a certain text string of ‘test’ in the file
    If yes
        echo ‘test string found’
    Else
        echo ‘test string NOT found’
Else
    Echo ‘no file today’
解决方案
@ECHO OFF
SETLOCAL
:: Point to the target directory. establish target file and string required
SET target=.
SET targfile=example.txt
SET targtxt=FIND me
::
SET targfile="%target%\%targfile%"
IF NOT EXIST %targfile% ECHO No file today& GOTO :EOF
:dfloop
SET filename=q%random%.q$q
SET fullname="%target%\%filename%"
IF EXIST %fullname% GOTO dfloop
:: create a dummy file dated today
COPY nul: %fullname% >nul
 FOR /f %%i IN ('dir %fullname% ^|find /i "%filename%"') DO SET today=%%i
DEL %fullname%
FOR /f %%i IN ('dir %targfile% ') DO IF %today%==%%i (SET today=)
IF DEFINED today ECHO No file today&GOTO :eof
FIND /i "%targtxt%" %targfile% >NUL
IF ERRORLEVEL 1 (ECHO test string NOT found) ELSE (ECHO test string found)

I've set the target directory to . - the current directory - for testing. Replace the . with your target directory name.

Looks for a string in the target file 'example.txt'

Now - that assumes that you are looking for a specific filename that may appear/be modified in a directory such as ...\myappdir\myapp.log

If you mean "any file [matching some filemask] that was created/modified today" is to be searched for the string then a slightly modified routine:

@ECHO OFF
SETLOCAL
:: Point to the target directory. establish target filemask and string required
SET target=\destdir
SET targfile=examp*.txt
SET targtxt=FIND me
::
SET targfile="%target%\%targfile%"
IF NOT EXIST %targfile% ECHO No file today& GOTO :EOF
:dfloop
SET filename=q%random%.q$q
SET fullname="%target%\%filename%"
IF EXIST %fullname% GOTO dfloop
:: create a dummy file dated today
COPY nul: %fullname% >nul
FOR /f %%i IN ('dir %fullname% ^|find /i "%filename%"') DO SET today=%%i
DEL %fullname%
SET count=0
FOR /f %%i IN ('dir %targfile% ') DO IF %today%==%%i (SET /a count+=1)
IF %count% equ 0 ECHO No file today&GOTO :eof
FOR /f "tokens=1*delims=:" %%i IN (
 'dir /b/a-d/o-d %targfile%^|findstr /n /v "*" '
  ) DO IF %%i leq %count% (
FIND /i "%targtxt%" "%target%\%%j" >NUL
IF NOT ERRORLEVEL 1 (SET today=)
)
IF DEFINED today (ECHO test string NOT found) ELSE (ECHO test string found)

Here, any file matching examp*.txt that has been created/modified today in \destdir will be examined for the target string.

这篇关于有没有在今天的修改日期的目录文件 - 批处理文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 22:08