Batch file 创建批处理文件以显示超过30分钟的文本文件

Batch file 创建批处理文件以显示超过30分钟的文本文件,batch-file,Batch File,我正在搜索仅显示文件夹中超过30分钟的文本文件的批处理文件 有人能帮我吗 @echo off setlocal set "t_dir=C:\testdir" set "Win32_D_path=%t_dir:\=\\%" for /f "skip=2 tokens=2 delims=,." %%W in ('wmic path Win32_Directory where name^="%Win32_D_path%" get C

我正在搜索仅显示文件夹中超过30分钟的文本文件的批处理文件

有人能帮我吗

    @echo off
    setlocal
        set "t_dir=C:\testdir"

        set "Win32_D_path=%t_dir:\=\\%"


        for /f "skip=2 tokens=2 delims=,." %%W in ('wmic path Win32_Directory where name^="%Win32_D_path%" get CreationDate /Format:csv') do set "dir_c_date=%%W"

        set dir_YYYY=%dir_c_date:~0,4%
        set dir_MM=%dir_c_date:~4,2%
        set dir_DD=%dir_c_date:~6,2%
        set dir_HH=%dir_c_date:~8,2%
        set dir_min=%dir_c_date:~10,2%
        set dir_sec=%dir_c_date:~12,2%

        set leap_year=n
        set /a ly=dir_YYYY %% 1
        if %ly% EQU 0 ( set leap_year=y ) else ( goto :elyc)
        set /a ly=dir_YYYY %% 100
        if %ly% EQU 0 ( set leap_year=n ) else ( goto :elyc)
        set /a ly=dir_YYYY %% 400
        if %ly% EQU 0 ( set leap_year=y ) else ( goto :elyc)

        :elyc
        set m31=01,03,05,07,08,10,12
        set m30=04,06,09,11


        set /a target_min=(dir_min+30)%%60
        if %target_min% LSS 10 set target_min=0%target_min%
        set /a target_hour=(dir_HH+(dir_min+30)/60)%%24
        if %target_hour% LSS 10 set target_hour=0%target_hour%
        set /a th_r=(dir_HH+(dir_min+30)/60)/24
        echo days modulus: %th_r%
        if %th_r% GEQ 1 (
            for  %%M in (%m31%) do (
                if %dir_MM% EQU %%M if %dir_DD% EQU 31 set /a target_day=1 && set /a target_month=dir_MM +1
                if %dir_MM% EQU %%M if %dir_DD% LSS 31 set /a target_day=dir_DD+1 && set /a target_month=dir_MM
                goto :ecm
            )
            for  %%M in (%m30%) do (
                if %dir_MM% EQU %%M if %dir_DD% EQU 30 set /a target_day=1 && set /a target_month=dir_MM +1
                if %dir_MM% EQU %%M if %dir_DD% LSS 30 set /a target_day=dir_DD+1 && set /a target_month=dir_MM
                goto :ecm
            )

            if "%leap_year%" EQU "n" if %dir_MM% EQU 02 if %dir_DD% EQU 28  set /a target_day=1 && set /a target_month=dir_MM +1
            if "%leap_year%" EQU "n" if %dir_MM% EQU 02 if %dir_DD% LSS 28  set /a target_day=dir_DD+1 && set /a target_month=dir_MM
            if "%leap_year%" EQU "y" if %dir_MM% EQU 02 if %dir_DD% EQU 29  set /a target_day=1 && set /a target_month=dir_MM +1
            if "%leap_year%" EQU "y" if %dir_MM% EQU 02 if %dir_DD% LSS 29  set /a target_day=dir_DD+1 && set /a target_month=dir_MM
            goto :ecm

        )
        set /a target_day=dir_DD
        set /a target_month=dir_MM

        :ecm
        if %target_day% LSS 10 set target_day=0%target_day%
        if %target_month% LSS 10 set target_month=0%target_month%
        if %target_month% GTR 12 ( set /a target_year=dir_YYYY+1 ) else (set /a target_year=dir_YYYY)
if %target_month% GTR 12 set target_month=01


        set  target_date=%target_year%%target_month%%target_day%%target_hour%%target_min%%target_sec%
        echo target date: %target_date%
        setlocal enableDelayedExpansion
        for /f "delims=" %%F in ('dir /b /s /a:-d %t_dir%') do (
            set "c_file=%%F"
            set "w32c_file=!c_file:\=\\!"
            for /f "skip=2 tokens=2 delims=,." %%D in ('WMIC DATAFILE WHERE name^="!w32c_file!" get CreationDate /Format:csv') do (
                if "%%D" GTR "%target_date%"  echo !c_file!
            )
        )
        endlocal


    endlocal

未经严格测试,需要WMIC

另一种选择是使用XXcopy(免费供个人使用),它粒度很小,可以只列出文件。

欢迎使用,向我们展示您的尝试,并询问详细问题,我们将尽力帮助您。提示:阅读帮助集和帮助呼叫,并查找%DATE%和%~t1@echo关闭cls模式500100 Title Xtime Notify setlocal enabledelayedexpansion:Loop set“Xtime=30”For/F“tokens=2,*delims=:“%%a in('echo%time%”)Do set CurrTime=%%a echo%CurrTime%For%%a in(*.txt)Do(set“Filename=%%a”echo%%a For/F“tokens=3 delims=:“%%b in(%%ta”)Do(设置“Ftime=%%b”设置/a check=CurrTime-Ftime IF!check!GEQ!Xtime!(echo%Filename%/f/Q%%~fsa)Else(goto next)):下一个goto循环