China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-06-28 13:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to write P processing that meets this function View 2,274 Replies 17
Floor 16 Posted 2007-08-19 00:57 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
```
:: Now it's moving only one file at a time.
:: If there are three or more files to compare, the one moved may not be the most recent.
:: Can only handle files from 2000 to 2099.

@echo off&set a=1&set b=1
setlocal ENABLEDELAYEDEXPANSION
for /f "delims=" %%a in ('dir/b *.txt') do call :ss "%%a"

rem +Third line content=file name
for /f "tokens=1-4 delims=_=" %%a in ('set _') do set +%%d=!+%%d!_%%a

rem __Serial number=file name first line content second line content
for /f "tokens=2* delims=_" %%a in ('set +') do (
if not "%%b"=="" set __!a!=%%a_%%b&set/a a+=1
)

set __>nul 2>nul||echo.&&echo No files to move&&echo.&&pause&&exit

:loop
for /f "tokens=1* delims==_" %%a in ('set __!b!') do set qua=%%b

for /f "tokens=1,2 delims=_" %%i in ("!qua!") do set qua1="%%i"&set qua2="%%j"
for /f "tokens=1-3 delims=" %%c in (!qua1!) do set wjm="%%c"&set dyh=%%d&set deh=%%e
for /f "tokens=1-3 delims=" %%c in (!qua2!) do set wj="%%c"&set dyhr=%%d&set dehs=%%e
call :duibi

set /a b+=1
if defined __!b! goto loop

rem Move files
if not exist c:\456 md c:\456
cls&echo\&echo The following are the files moved......&echo\
for /f "tokens=2 delims==" %%a in ('set ok^|sort') do (
echo %%a
move %%a c:\456
)
echo.&pause
start "" "c:\456"
exit

rem Set the specified content of the first three lines of the file as variables Format: _file name=first line content second line content third line content
:ss
set ls=0
rem If the operation is not successful, delete the space after delims= in the following line and enter a tab key.
for /f "tokens=2 delims= " %%b in ('findstr .* %1') do (
set/a ls+=1
if !ls! lss 4 (set "_%~1=!_%~1!_%%b") else goto :eof
)
goto :eof

rem Judge date and time
:duibi
set/a ook+=1
if "!dyh!"=="!dyhr!" (
if !deh! leq !dehs! (set ok!ook!=!wj!) else (set ok!ook!=!wjm!)
goto :eof
)

for /f "tokens=1-3 delims=/" %%o in ("!dyh!") do set nian=20%%q&set yue=%%o&set ri=%%p
for /f "tokens=1-3 delims=/" %%o in ("!dyhr!") do (
set ni_an=20%%q&set y_ue=%%o&set r_i=%%p
)

if !nian!-!yue!-!ri! lss !ni_an!-!y_ue!-!r_i! (
set ok!ook!=!wj!&goto :eof
) else set ok!ook!=!wjm!
goto :eof
```
致精致简!
Floor 17 Posted 2007-08-20 15:29 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
If there are three or more files for comparison, the one moved is not necessarily the most recent in time. Can it be done to only move the most recent one? Maybe I need to trouble you to improve it. thanks!
Floor 18 Posted 2007-08-20 16:37 ·  中国 湖南 娄底 电信
银牌会员
★★★
Credits 2,268
Posts 879
Joined 2006-12-19 16:23
19-year member
UID 73968
Gender Male
Status Offline
It's too troublesome. I've lost interest in thinking about this question. Remember to state the requirements clearly at one time when asking questions in the future.
致精致简!
Forum Jump: