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-05 03:15
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to classify files according to the status of TAR files? View 2,203 Replies 22
Original Poster Posted 2007-06-13 22:23 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Dear experts:

Please help me write a batch processing that can implement the following functions.

1. Suppose there are many .TAR files in the C:\log folder (compressed files), and each .TAR file has only one state, either TP or TF (you can tell from the .TAR file)

2. To distinguish the .TAR files with TP or TF, for example: move the .TAR files with TF to the C:\log\TF\ folder,

3. Since the original .TAR file cannot be attached, only the content of the .TAR file is attached here for your reference
************************************************************
SBS7152297IB
CWHP
BWHP UI
Nhuawhpfct11
PFVT
s0
D2217.scr
R???
nW10110641
rREL
OC900260
L29
p11
W???

06/01/07 20:13:36
TF
FWRCVP_Disable Heartbeat
>WIDE_RECEIVE_PACKET (Disable Heartbeat Broadcast packet)
>RcvPacket() returned an error
>Timeout getting packet byte
MWide_FW_Version
d0x11
************************************************************

[ Last edited by bjsh on 2007-7-31 at 02:28 PM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
lxmxn -2 2007-06-16 21:47
Floor 2 Posted 2007-06-13 22:39 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Does the LZ mean that as long as the TAR file contains TF, it is put into the TF folder, and if it contains TP, it is put into the TP folder?
Floor 3 Posted 2007-06-13 22:46 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
Yes, can it be done? Thank you for your timely reply
Floor 4 Posted 2007-06-13 23:13 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
I'm not familiar with TAR files at all. I only know they are compression files under Linux.

How was the content of the owner's file extracted?

Is it the file name or just the text content?
Floor 5 Posted 2007-06-13 23:26 ·  中国 广东 广州 黄埔区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
First, point to the.TAR file, then right-click the mouse and select Notepad to open. It looks like a compressed file on the surface, but actually the content is text content
Floor 6 Posted 2007-06-14 00:34 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
This can be referred to.
@echo off&setlocal enabledelayedexpansion
if not exist TF md TF
if not exist TP md TP
for /f %%i in ('dir /b *.txt') do (
find /c "TF" %%i
if !errorlevel!==0 copy %%i TF\%%i&del /q /f %%i
)
copy *.txt TP\*.txt
del /q /f *.txt

I assume there are many text files in the current folder, and they only contain "TF" or "TP" characters.
Floor 7 Posted 2007-06-14 15:05 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
First, thank you to the experts. The basic functions can be realized, but the.TAR files containing TP or TF characters cannot be accurately distinguished 100%. For example, the following two filenames of.TAR files are found temporarily. Their contents contain TP characters, but they are still placed in the folder with TF. Can you help me study it again? Thank you first.

RE0724000R5CA(6-13-2007 16-3-38).TAR ---> is the file name

KM107230000JLA(6-9-2007 12-41-29).TAR---> is the file name
Floor 8 Posted 2007-06-14 15:18 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Mistake, forgot to ask the thread starter if the file name contains spaces. Hehe
Similar to
@echo off&setlocal enabledelayedexpansion
if not exist TF md TF
if not exist TP md TP
for /f "delims=" %%i in ('dir /b *.txt') do (
find /c "TF" "%%i"
if !errorlevel!==0 copy "%%i" TF\"%%i"&del /q /f "%%i"
)
copy *.txt TP\*.txt
del /q /f *.txt

Not tested, just take a look first.
Floor 9 Posted 2007-06-14 20:56 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
The file name is the same as other file names, (this file name is generated automatically by the system), also tried the latest one you just gave me but it still doesn't work. Can it be convenient to give me your email address? I will send you the relevant.TAR files to help me take a look because I don't know how to attach those files here. Thanks in advance!
Floor 10 Posted 2007-06-15 00:06 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Click the quote reply to add an attachment.
@echo off&setlocal enabledelayedexpansion
if not exist TF md TF
if not exist TP md TP
for /f "delims=" %%i in ('dir /b *.txt') do (
findstr /b /r "\<TF\>" "%%i"
if !errorlevel!==0 copy "%%i" TF\"%%i"&del /q /f "%%i"
)
copy *.txt TP\*.txt
del /q /f *.txt


[ Last edited by wudixin96 on 2007-6-15 at 10:56 AM ]
Floor 11 Posted 2007-06-15 14:53 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
I tested it, and for the time being, no problems were found. Still, the experts are amazing! I'm really too stupid. Experts, now there's another question I'd like to ask. When a normal batch file runs, a black window flashes in front of the screen. Is there a way to make the batch file run in the background, without a black window flashing in front of the screen? Please give me some advice.
Floor 12 Posted 2007-06-15 15:03 ·  中国 浙江 衢州 中移铁通
银牌会员
★★★
Credits 1,928
Posts 931
Joined 2007-01-06 11:46
19-year member
UID 75624
Gender Male
Status Offline
Brother, you're overpraising. Actually, I'm also a newbie. Just started learning.

To hide the running batch processing, please use the "Search" function of the forum.
Floor 13 Posted 2007-06-15 16:34 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
set batname=WScript.CreateObject("WScript.Shell")
batname.run "batpath",0

Just save it as a VBS script and run it.

[ Last edited by lililulula on 2007-6-15 at 04:35 PM ]
Floor 14 Posted 2007-06-15 16:50 ·  中国 广东 广州 白云区 电信
初级用户
★★
Credits 132
Posts 62
Joined 2007-06-05 23:27
19-year member
UID 90371
Gender Male
Status Offline
The meaning of floor 13 I still don't understand. Can you explain it in detail? I mean I use Windows--->Control panel-->Scheduled Task to schedule a time to run this batch regularly. When it runs, is there a way to make the batch run in a hidden way or other ways, in short, don't let people see the black screen flashing.
Floor 15 Posted 2007-06-15 17:09 ·  中国 上海 浦东新区 电信
中级用户
★★
Credits 302
Posts 138
Joined 2007-03-29 02:33
19-year member
UID 83224
Gender Male
Status Offline
Save the above code as a VBS file. In the code, `batpath` is the absolute path of your bat file, and then run this VBS script in the task scheduler
Forum Jump: