hnfeng 当前离线
五级士官
评分人数
77七 当前离线
中校
@echo off set str=2024/01/01 00:00 setlocal enabledelayedexpansion for /f "delims=" %%i in ('dir /b /s /a-d ^|find /v "%~nx0"') do ( if "%%~ti" geq "!str!" ( set str=%%~ti ) ) echo %str% endlocal pause复制代码
TOP
czjt1234 当前离线
少校
没看懂,到底要获取什么最新的日期,是文件还是文件夹? 可能是文件夹吧,如果是文件,那就必须逐个判断 ... czjt1234 发表于 2024-12-4 15:06
77七 发表于 2024-12-4 14:40
@echo off&setlocal EnableDelayedExpansion&cd /d "%~dp0"&title %~nx0 set LogFile="%~dpn0.Log" if exist _temp.txt del /f /q _temp.txt for /f "delims=" %%d in ('dir /b /ad') do ( call :DoGetNewestDate %%d ) echo;&pause exit :DoGetNewestDate echo 正在查询文件夹:%~1 ... dir /s /a-d /o-d "%~1" | findstr /bric:"202[4-5]-[0-1][0-9]-[0-3][0-9]*">_temp.txt for /f "tokens=*" %%f in ('dir /b _temp.txt') do ( if %%~zf EQU 0 ( echo %~1 找不到文件>>%LogFile% goto :EOF ) ) set n=1 for /f "tokens=*" %%i in ('sort /r _temp.txt') do ( if !n! EQU 1 ( echo %~1 %%i echo %~1 %%i>>%LogFile% set /a n+=1 ) ) del /f /q _temp.txt goto :EOF复制代码
qixiaobin0715 当前离线
大校
@echo off (for /f "delims=" %%i in ('dir /s /b /a-d') do if not "%%i"=="%~dp0" echo,%%~ti %%i)>temp1 sort /r temp1>temp2 set /p str=<temp2 echo,%str% del temp? pause复制代码
回复 hnfeng 文件夹有多少个?文件数量共有多少? 77七 发表于 2024-12-4 16:21
@echo off cd /d "%~dp0" setlocal enabledelayedexpansion for /r /d %%d in (*) do ( pushd "%%d" call :1 popd ) echo !str! endlocal pause exit :1 for /f "delims=" %%i in ('2^>nul dir /b /a-d /o-d') do ( if "%%~ti" geq "!str!" ( set str=%%~ti ) exit /b ) exit /b复制代码
回复 hnfeng 主要看看是什么数量级别的,代码肯定要因地制宜 如果共几千个文件,不如就2楼代码, ... 77七 发表于 2024-12-4 17:21
aloha20200628 当前离线
@echo off &if "%~1"=="" (exit/b) setlocal &set "_td=d:\tmp" (md "%_td%" &cd "%_td%" &del /q "?._") 2>nul dir /s/a-d/tw/o-d "%~1">"d._" sort /r "d._" /o "s._" set/p _f=<"s._" findstr /n ".*" "d._">"n._" findstr /iec:"%_f%" "n._">"f._" for /f "delims=:" %%n in (f._) do set/a "n=%%n-2" findstr /ib "%n%:" "n._">"d._" for /f "tokens=3* delims= " %%a in ("%_f%") do set "_f=%%b" for /f "tokens=1* delims=: " %%a in (d._) do set "_d=%%b" set "ff=%_d:~0,-4%\%_f%" echo,%ff% del/q "?._" 2>nul&endlocal&pause&exit/b复制代码
Five66 当前离线
上尉
dir /s/a-d/tw/o-d "%~1"|sort /r复制代码
回复 hnfeng 其实11楼代码中第6行已拿到全目录下的最新文件名了(变量 _f),只是缺少其路径,其后的代 ... aloha20200628 发表于 2024-12-5 09:41