Board logo

标题: 如何根据TAR文件的状态把文件分类? [打印本页]

作者: joshualaw     时间: 2007-6-13 22:23    标题: 如何根据TAR文件的状态把文件分类?

各位高手:
请帮我写一个能实现下列功能批处理。

1. 假设在 C:\log 文件夹有许多 .TAR 文件(已压缩的文件),而且每个.TAR文件只有一种状态,要么是 TP要么是 TF (你可从 .TAR 文件看出来)

2. 要把带有TP或TF的 .TAR文件区别开来,例如:把带有TF的 .TAR文件移到 C:\log\TF\文件夹里,

3.由于无法附上.TAR原文件,只有附上.TAR文件的内容在此给各位参照
************************************************************
SBS7152297IB
CWHP
BWHP UI
Nhuawhpfct11
PFVT
s0
D2217.scr
R???
nW10110641
rREL
OC900260
L29
p11
W???
[06/01/07 20:13:16
]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 ]
作者: wudixin96     时间: 2007-6-13 22:39
楼主的意思是说,只要TAR文件中包含TF的就放入TF文件夹,TP的就放入TP文件夹?
作者: joshualaw     时间: 2007-6-13 22:46
是的,能做的到吗,谢谢您的及时回复
作者: wudixin96     时间: 2007-6-13 23:13
对TAR文件一点不熟悉。只知道是Linux下的压缩文件。

楼主的文件内容是如何提取出来的?

是文件名称,还是只是文本内容?
作者: joshualaw     时间: 2007-6-13 23:26
先指着.TAR文件后右击鼠标选记事本打开的,外表看是一个压缩文件,其实内容是文本内容
作者: wudixin96     时间: 2007-6-14 00:34
这个可以参考一下。
@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
偶假设当前文件夹下有许多文本文件,其中也只包含TF或TP字符。
作者: joshualaw     时间: 2007-6-14 15:05
先谢谢高手,基本功能可以实现但还不能100%精确的把含有TP 或 TF 字符的.TAR文件区别开来,例如: 暂时发现下列两个文件名.TAR 文件,其内容是含有TP 的字符,但还是放在 TF的文件夹理,能否帮我再研究研究看,先谢了.

RE0724000R5CA(6-13-2007 16-3-38).TAR --->是文件名

KM107230000JLA(6-9-2007 12-41-29).TAR--->是文件名
作者: wudixin96     时间: 2007-6-14 15:18
失误,忘问楼主的文件名是否含空格了。呵呵
类似的
@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
没测试,先看看吧。
作者: joshualaw     时间: 2007-6-14 20:56
文件名跟其它文件名一样的,(这文件名是系统自动产生的), 也试了你刚刚给我最新的但还是不行,能否方便给我你的 email address, 我把相关.TAR 文件发给你帮我看看因为我不知道怎样把那些文件附在这里.先谢拉!
作者: wudixin96     时间: 2007-6-15 00:06
点引用回复,就可以添加附件了。
@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 ]
作者: joshualaw     时间: 2007-6-15 14:53
我测试了一下,暂时没有发现问题,还是高手厉害啊,我真的太笨拉,高手,现还有一问题请教,正常的批处理运行时,会在屏幕前闪一下黑色的窗口,能否有办法让批处理在后台运行,不要会在屏幕前闪一下黑色的窗口, 请赐教
作者: wudixin96     时间: 2007-6-15 15:03
兄台过奖了,其实偶也一菜鸟。刚入门而已。

要隐藏运行批处理,请使用论坛的“搜索”功能。
作者: lililulula     时间: 2007-6-15 16:34


  Quote:
set batname=WScript.CreateObject("WScript.Shell")
batname.run "batpath",0

保存为vbs脚本运行即可

[ Last edited by lililulula on 2007-6-15 at 04:35 PM ]
作者: joshualaw     时间: 2007-6-15 16:50
13 楼的意思我还不明白,能否详细说明一下, 我的意思是我用Windows--->Control panel-->Scheduled Task 来排一时间定期运行这一批处理,当运行时,能否有办法让批处理采用"隐藏的方式或其它的方式运行", 总之不要让人看到有黑色屏幕闪烁就行啊,
作者: lililulula     时间: 2007-6-15 17:09
你将上段代码保存成vbs文件,代码里面的batpath为你bat文件的绝对路径,然后计划任务中运行这个vbs脚本
作者: HAT     时间: 2007-6-15 20:30
除了13楼的VBS可以用隐藏的方式运行之外
还可以为批处理创建一个快捷方式
然后schedule这个快捷方式
作者: HAT     时间: 2007-6-15 20:31
使用at命令添加的计划任务也可以隐藏运行
作者: joshualaw     时间: 2007-6-15 22:06
能否详细告知我怎样用at命令吗
作者: HAT     时间: 2007-6-15 23:49
//能否详细告知我怎样用at命令吗

rem 下午1点15分运行
at 13:15 C:\test.bat

  Quote:
C:\>at /?
The AT command schedules commands and programs to run on a computer at
a specified time and date. The Schedule service must be running to use
the AT command.

AT [\\computername] [ [id] [/DELETE] | /DELETE [/YES]]
AT [\\computername] time [/INTERACTIVE]
    [ /EVERY:date[,...] | /NEXT:date[,...]] "command"

\\computername     Specifies a remote computer. Commands are scheduled on the
                   local computer if this parameter is omitted.
id                 Is an identification number assigned to a scheduled
                   command.
/delete            Cancels a scheduled command. If id is omitted, all the
                   scheduled commands on the computer are canceled.
/yes               Used with cancel all jobs command when no further
                   confirmation is desired.
time               Specifies the time when command is to run.
/interactive       Allows the job to interact with the desktop of the user
                   who is logged on at the time the job runs.
/every:date[,...]  Runs the command on each specified day(s) of the week or
                   month. If date is omitted, the current day of the month
                   is assumed.
/next:date[,...]   Runs the specified command on the next occurrence of the
                   day (for example, next Thursday).  If date is omitted, the
                   current day of the month is assumed.
"command"          Is the Windows NT command, or batch program to be run.


作者: joshualaw     时间: 2007-6-16 10:19
我想在网络上以“cdghua******"开头所有电脑上,每天每隔10分钟重复运行 C:\test.bat 批处理,请用AT命令帮我完成,先谢啦
作者: joshualaw     时间: 2007-6-16 20:46


  Quote:
Originally posted by lililulula at 2007-6-15 04:34 PM:

保存为vbs脚本运行即可

[ Last edited by lililulula on 2007-6-15 at 04:35 PM ]

用vbs脚本可实现,谢了,但现有一问题请教,假设vbs脚本有问题的话,当我运行vbs脚本时,会自动弹出一个带有“Windows 脚本宿主“标题的错误对话窗口,上面有些提示信息,请问能否有办法让这一个带有“Windows 脚本宿主“标题的错误对话窗口出现呢?请赐教
作者: wudixin96     时间: 2007-6-16 20:54
楼主有看这个帖子吗?

http://www.cn-dos.net/forum/viewthread.php?tid=23846
作者: joshualaw     时间: 2007-6-18 14:12
看了那些后似乎还是不能解决,要让带有“Windows 脚本宿主“标题的错误对话窗口出现,各位高手请给我把代码写在这吧,

[ Last edited by joshualaw on 2007-6-19 at 11:32 PM ]
附件 1: error windows.JPG (2007-6-19 23:30, 23.03 K,下载次数: 2)