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-08-01 22:12
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Closed] Regularly clear all contents of log.txt every 25 minutes View 2,520 Replies 19
Original Poster Posted 2006-07-22 10:04 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
Newbie seeking help: I hope everyone can solve my problem.

There is a text file log.txt in my D:\ directory.

The log.txt file will be written with some content regularly. I hope to use a batch script to clear all the content in log.txt every 25 minutes.

That is, this batch script is an infinite loop to regularly delete all the content in log.txt.

Please help me. For this file, my head is big, and I don't know batch scripting.

Please help~~~~~~~~~

[ Last edited by willsort on 2006-7-22 at 19:29 ]
Floor 2 Posted 2006-07-22 10:42 ·  中国 广东 东莞 电信
初级用户
Credits 34
Posts 13
Joined 2006-07-20 19:11
20-year member
UID 58929
Gender Male
Status Offline
It seems that you need to use AT task commands (or other similar software) to execute batch files regularly to achieve the effect. I wonder if there are such commands in your system
Floor 3 Posted 2006-07-22 10:59 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
I don't know what an AT task instruction is~~~~~~~
Floor 4 Posted 2006-07-22 11:10 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Here's the translation:

  Here's the most straightforward one:

@echo off
:loop
del /q d:\log.txt
echo.>d:\log.txt
ping 127.1 -n 1500 >nul 2>nul
goto loop


[ Last edited by namejm on 2006-7-22 at 11:11 ]
Floor 5 Posted 2006-07-22 11:31 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
Excuse me, what is the above batch processing? Could you please explain it to me, little brother?

Begging~
Floor 6 Posted 2006-07-22 11:35 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
It doesn't work~~~~~After running, only a CMD window pops up.. and then nothing runs.
Floor 7 Posted 2006-07-22 11:45 ·  中国 湖北 武汉 电信
中级用户
★★
Credits 245
Posts 103
Joined 2006-06-30 00:00
20-year member
UID 57801
Gender Male
Status Offline
Well, as long as it achieves your purpose, what else do you want?
Floor 8 Posted 2006-07-22 11:51 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
It doesn't work~~~~~After running, only a CMD window pops up.. and then nothing runs.
Floor 9 Posted 2006-07-22 11:54 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
Oh.. thank you ah~~~~~~ Now the content in the file has been cleared.. May I ask where to set the time limit ah~~~~~~~~`
Floor 10 Posted 2006-07-22 12:11 ·  中国 辽宁 大连 教育网
中级用户
★★
DOS之友
Credits 332
Posts 168
Joined 2005-10-06 00:00
20-year member
UID 43171
Gender Male
From 天涯
Status Offline
Hehe. At first, I also thought of at. But it didn't work well. Later, during the meal time, I thought of Wu Nai He's signature. Use ping to measure time delay. I didn't expect that someone had already thought of it when I came back. It's really fast.
Floor 11 Posted 2006-07-22 12:31 ·  中国 广东 广州 天河区 电信
初级用户
Credits 24
Posts 8
Joined 2006-07-22 00:26
20-year member
UID 58998
Status Offline
Thank you~~~~~~~I love everyone~~~~~~
Floor 12 Posted 2006-07-22 12:42 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The secret of the delay is in the sentence "ping 127.1 -n 1500 >nul 2>nul". Use the method of pinging the local machine (127.0.0.1 can be abbreviated as 127.1) to delay. 1500(s) = 25(min)×60. You can minimize the popped-up window and terminate it by pressing Ctrl+C.
Floor 13 Posted 2006-07-22 15:04 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
You can clear the original file without using "del /q d:\log.txt" by directly using "echo.>>d:\log.txt" to overwrite and clear it.

Here is one for hiding the window:
Startup file: Start.bat
@echo off
echo Set WshShell = WScript.CreateObject("WScript.Shell")>Wait.vbs
echo Set fso = Wscript.CreateObject("Scripting.FileSystemObject")>>Wait.vbs
echo fso.DeleteFile("Wait.vbs")>>Wait.vbs
echo WshShell.Run "ClearLog.bat",vbhide>>Wait.vbs
Wait.vbs
exit

Automatic loop to clear file: ClearLog.bat
@echo off
:loop
echo.>d:\log.txt
if EXIST C:\QuitLog.txt goto End
echo Set WshShell = WScript.CreateObject("WScript.Shell")>%Temp%\Wait.vbs
echo Set fso = Wscript.CreateObject("Scripting.FileSystemObject")>>%Temp%\Wait.vbs
echo fso.DeleteFile("%Temp%\Wait.vbs")>>%Temp%\Wait.vbs
echo WScript.Sleep 1500000>>%Temp%\Wait.vbs
%Temp%\Wait.vbs
goto loop

:End
if EXIST C:\QuitLog.txt del C:\QuitLog.txt
exit

1500000 is the delay of 1500000 milliseconds (25 minutes)

Quit automatic file clearing: QuitClear.bat
@echo off
echo.>C:\QuitLog.txt
exit

Start.bat and ClearLog.bat must be placed in the same directory. Run Start.bat to start.
If you need to end, run QuitClear.bat, and it will automatically exit after the next time d:\log.txt is cleared

[ Last edited by zxcv on 2006-7-22 at 21:33 ]
Floor 14 Posted 2006-07-22 15:11 ·  中国 辽宁 大连 教育网
中级用户
★★
DOS之友
Credits 332
Posts 168
Joined 2005-10-06 00:00
20-year member
UID 43171
Gender Male
From 天涯
Status Offline
echo.>d:\log.txt
Modify to copy nul d:\log.txt >nul 2>nul
I think this would be better

[ Last edited by IceCrack on 2006-7-22 at 15:12 ]
Floor 15 Posted 2006-07-22 15:18 ·  中国 广西 玉林 博白县 电信
金牌会员
★★★★
Credits 3,687
Posts 1,467
Joined 2005-08-08 12:00
20-year member
UID 44210
Status Offline
Originally posted by IceCrack at 2006-7-22 15:11:
echo.>d:\log.txt
Modify this to copy nul d:\log.txt >nul 2>nul
I think this will be better

[ Last edited by IceCrack on 2006-7-22 at 15:12 ]

Not bad, it generates an empty txt file
Forum Jump: