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-07-31 22:26
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to find all files created between 17:00 and 17:25 in one day? View 3,994 Replies 16
Original Poster Posted 2006-11-26 07:33 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
How to find all files created between 17:00 and 17:25 in one day?
@echo off
set /p d=Please enter the full path:
set /p start_time=Please enter the start time of the file creation:
set /p end_time=Please enter the end time of the file creation:
for /f "tokens=3,*" %%i in ('dir /a-d/od/t:C "%d%" ^| findstr /b /c:"%start_time%" /c:"%end_time%"') do (echo %%j>>d:\22.txt)
pause
I know this part. I don't know how to find within a certain time range. Can anyone help me modify it?
Floor 2 Posted 2006-11-26 08:40 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  Try this, each input should be standard, date example: 2006-11-25, time example (24-hour system): 09:20, 23:50

@echo off
set/p d_=Please enter the path to search (default current folder):
set/p date_=Please enter the creation date of the file to query:
if not defined date_ goto error
set/p time1=Enter start time:
if not defined time1 goto error
set/p time2=Please enter end time:
if not defined time2 goto error
cls
echo Search results:&&echo;
for /f "skip=5 tokens=1,2,4*" %%a in ('dir /a-d/od/tc "%d_%" ^| find "%date_%"') do (
if %%b geq %time1% if not %%b geq %time2% (
echo %%c
)
)
pause
goto :eof
:error
echo Input error
pause


[ Last edited by lxmxn on 2006-11-27 at 10:21 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
anqing +2 2006-11-26 09:29
Floor 3 Posted 2006-11-26 08:58 ·  中国 江苏 南京 电信
高级用户
★★
Credits 623
Posts 214
Joined 2006-09-22 20:48
19-year member
UID 63387
Status Offline
I tried it, but couldn't find the result. The code should be modified further.
Floor 4 Posted 2006-11-26 09:14 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline

  Re tianzizhi :

  No way, I tried it and it worked. Unless the date or time you entered is in the wrong format, or there are no files within the time or date you specified.


[ Last edited by lxmxn on 2006-11-26 at 09:15 AM ]
Floor 5 Posted 2006-11-26 09:15 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
```batch
@echo off
set/p d_=Please enter the path to be searched (default current folder):
:error
set/p date_=Please enter the creation date of the file to be queried:
if not defined date_ goto error
set/p time1=Enter the start time:
if not defined time1 goto error
set/p time2=Please enter the end time:
if not defined time2 goto error
cls
echo Search results:&&echo;
for /f "tokens=1,2,4*" %%a in ('dir /a-d/od/tc "%d_%" ^| find "%date_%"') do if %%b geq %time1% if not %%b geq %time2% echo %%c
pause
```
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
anqing +2 2006-11-26 09:30
Floor 6 Posted 2006-11-26 09:28 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Floor 7 Posted 2006-11-26 09:54 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
The creation time of my file is: 16:16:48. I set the start time to 16:15 and the end time to 16:17. As a result, no file was found. But if I set the start time to 16:14, I can find it. Why is that?

I created a new file again. No matter how I set the time, I can find it. Then, I set the time as above again, and as a result, I found it.

I think DOS is sometimes unstable, just like an operating system. Actually, DOS is also a kind of operating system, right? I don't know if this understanding is correct.

In addition, I want to perform a time period search for files on the entire disk, such as drive C or D. How should I add code?

[ Last edited by anqing on 2006-11-26 at 10:20 AM ]
Floor 8 Posted 2006-11-26 10:06 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
In addition, if I want to search in the C drive, this p can't find it either
Floor 9 Posted 2006-11-27 06:34 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
I want to search for files in a time period on the entire disk, such as drive C or D. How to add code?

Waited a day, why no one answers?
Floor 10 Posted 2006-11-27 13:01 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
wmic datafile where "InstallDate>'20061126200000.000000+480'  and drive='d:' and InstallDate<'20061126230000.000000+480'" get caption

The above is an example of finding files created on drive D between 20:00 and 23:00 on November 26, 2006. You can specify the drive letter, directory, and other filtering conditions by yourself.
P.S: If you search the entire disk, it may run for too long and cause "not responding" (when the number of files is large).
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
lxmxn +3 2006-11-27 13:04
Floor 11 Posted 2006-11-27 21:59 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
Thank you, moderator. I want to implement searching the entire drive letter within a specified time period in the above batch processing.
Floor 12 Posted 2006-11-27 22:24 ·  中国 吉林 四平 联通
高级用户
★★★
Credits 859
Posts 413
Joined 2006-08-14 21:55
19-year member
UID 60532
Status Offline
@echo off
set/p d_=Please enter the path to be searched (default current folder):
set/p date_=Please enter the creation date of the file to be queried:
if not defined date_ goto error
set/p time1=Enter start time:
if not defined time1 goto error
set/p time2=Please enter end time:
if not defined time2 goto error
cls
echo Search results:&&echo;
for /f "skip=5 tokens=1,2,4*" %%a in ('dir /a-d/s/od/tc "%d_%" ^| find "%date_%"') do (
if %%b geq %time1% if not %%b geq %time2% (
echo %%c
)
)
pause
goto :eof
:error
echo Input error
pause
To modify it to search for files created in the entire drive letter and specified paths, you can change "%d_%" to "D:\" (assuming you want to search drive D, adjust according to actual situation) and handle the input to support both entire drive and specific paths. For example:

@echo off
set /p d_=Please enter the path to be searched (enter the drive letter directly to search the entire drive, such as D:):
if "%d_"=="" set d_=.
set/p date_=Please enter the creation date of the file to be queried:
if not defined date_ goto error
set/p time1=Enter start time:
if not defined time1 goto error
set/p time2=Please enter end time:
if not defined time2 goto error
cls
echo Search results:&&echo;
for /f "skip=5 tokens=1,2,4*" %%a in ('dir /a-d/s/od/tc "%d_%" ^| find "%date_%"') do (
if %%b geq %time1% if not %%b geq %time2% (
echo %%c
)
)
pause
goto :eof
:error
echo Input error
pause
Floor 13 Posted 2007-01-11 04:17 ·  中国 广西 北海 电信
初级用户
Credits 54
Posts 18
Joined 2005-11-05 01:38
20-year member
UID 44610
Status Offline
lxmxn..If the file that meets the conditions contains spaces, echo %%c can only display part of it..Should use echo %%c %%d bar.

@echo off
set /p d_=Please enter the path to be searched (default current folder):
if not defined d_ (set d_=%cd%)
echo The query path has been set to %d_%
set /p date_=Please enter the creation date of the file to be queried:
if not defined date_ (for /f %%a in ("%date%") do (set date_=%%a))
echo The file with the creation date %date_% has been set.
set /p time1=Enter the start time:
if not defined time1 (set time1=00:00)
set /p time2=Enter the end time:
if not defined time2 (set time2=24:00)
cls

echo Search results: && echo.
for /f "tokens=1,2,3,4*" %%a in ('dir /a-d/s/od/tc "%d_%" ^| find "%date_%"') do (
if %%b geq %time1% (
if %%b leq %time2% (
echo %%d %%e
)
)
)

echo.
pause >nul

[ Last edited by zhoung0 on 2007-1-11 at 04:32 AM ]
Floor 14 Posted 2007-02-12 12:23 ·  中国 福建 厦门 电信
新手上路
Credits 2
Posts 1
Joined 2007-02-10 11:37
19-year member
UID 79160
Gender Male
Status Offline
Anqing hello!
My requirement is similar to yours. I need to find out the files generated at 9 PM every day and 9 PM the previous day.
I'm a complete beginner and don't know how to compile this batch processing program. Please help me take a look
Floor 15 Posted 2007-02-12 13:18 ·  中国 陕西 西安 电信
铂金会员
★★★★
Credits 5,212
Posts 2,478
Joined 2007-02-08 23:39
19-year member
UID 79003
Gender Male
Status Offline
@echo off
setlocal enabledelayedexpansion
set /p time1=Enter start time (format HH:MM:SS):
set /p time2=Enter end time (format HH:MM:SS):

set StartTime=%date:~0,4%%date:~5,2%%date:~8,2%%time1:~0,2%%time1:~3,2%%time1:~6,2%
set EndtTime=%date:~0,4%%date:~5,2%%date:~8,2%%time2:~0,2%%time2:~3,2%%time2:~6,2%

wmic datafile where "InstallDate>'%StartTime%.000000+480' and drive='d:' and InstallDate<'%EndtTime%.000000+480'" get caption>Result.txt

This seems to only check.dat files. How to change it to all?
Forum Jump: