|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『楼 主』:
[已解决]如何获取一符字符串中指定字符开始的n个字符
使用 LLM 解释/回答一下
20041119.WindowsXP-KB886677-x86-chs.exe
上面是一个文件字,这样子的文件名有多个,但也不是完全有规则的
现在要获取的字符串中以kb开始的8个字符,即kb******......
以下是我要达到的目的要求
一,一个文本文件,包含内容如下
20041119.WindowsXP-KB886677-x86-chs.exe
windowsmedia-KB885836-x86-CHS.exe
Windows-KB890830-V1.34.exe
KB939653.exe
二,要做的批处理命令为
20041119.WindowsXP-KB886677-x86-chs.exe
/x:.\kb886677
20041213.WindowsXP-KB873339-x86-CHS.exe /x:.\kb873339
windowsmedia-KB885836-x86-CHS.exe /x:.\KB885836
Windows-KB890830-V1.34.exe /x:.\KB890830
KB939653.exe /x:.\KB939653
三,请各位兄弟帮忙写个批处理
for /f "tokens=1" %%i in (hotfix.txt) do (
@echo 正在提取 Windows XP 更新 %%i && @(%%i /x:.\***这里KB目录名不知道怎么提取了***)
)
那位大哥指点一下!!!!
Last edited by nghr on 2007-10-21 at 12:43 PM ]
20041119.WindowsXP-KB886677-x86-chs.exe
The above is a file name, and there are multiple such file names, but they are not completely regular.
Now, we need to obtain the 8-character string starting with kb, that is, kb******......
The following are the purpose requirements I want to achieve:
1. A text file contains the following content:
20041119.WindowsXP-KB886677-x86-chs.exe
windowsmedia-KB885836-x86-CHS.exe
Windows-KB890830-V1.34.exe
KB939653.exe
2. The batch processing commands to be done are:
20041119.WindowsXP-KB886677-x86-chs.exe /x:.\kb886677
20041213.WindowsXP-KB873339-x86-CHS.exe /x:.\kb873339
windowsmedia-KB885836-x86-CHS.exe /x:.\KB885836
Windows-KB890830-V1.34.exe /x:.\KB890830
KB939653.exe /x:.\KB939653
3. Please help brothers write a batch processing:
for /f "tokens=1" %%i in (hotfix.txt) do (
@echo 正在提取 Windows XP 更新 %%i && @(%%i /x:.\***Here I don't know how to extract the KB directory name***)
)
Please give me some advice, big brother!!!!
Last edited by nghr on 2007-10-21 at 12:43 PM ]
|
|
2007-10-20 14:32 |
|
|
junchen2
高级用户
   
积分 537
发帖 219
注册 2007-8-4 来自 杭州--半山
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
echo off
@for /f "tokens=1-4 delims=-" %%a i n (hotfix.txt) do echo %%a-%%b-%%c-%%d /x:.\%%b
pause
@echo off
@for /f "tokens=1-4 delims=-" %%a in (hotfix.txt) do echo %%a-%%b-%%c-%%d /x:.\%%b
pause
|
|
2007-10-20 15:04 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
感谢二楼的兄弟!!!!你的这个有点小问题echo %%前加上@应该可以了
不能执行,执行的时候自动的跳过了,实际上等于没有执行,我的意思是这样子的,只要提取文件名字包含-kb****-的字符串,因为有的文件名是没有日期的,有的也没有chs的!!!
如果是不规则的文件名呢?但有一个共享点都是包含KB******八个字符的,如何编写?
Last edited by nghr on 2007-10-20 at 03:37 PM ]
Thanks to the brother on the second floor!!!! There is a small problem with yours. Adding @ before echo %% should work.
It can't be executed. When executing, it automatically skips, actually it's like not executed. I mean like this, as long as it extracts the string whose file name contains -kb****-. Because some file names have no date, and some have no chs!!!
What if the file name is irregular? But there is a common point that all contain 8 characters of KB******. How to write it?
Last edited by nghr on 2007-10-20 at 03:37 PM ]
|
|
2007-10-20 15:28 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
dir /b |find "KB" >hotfix.txt
for /f "tokens=1-4 delims=-" %%a in (hotfix.txt) do @echo 正在提取 Windows XP 更新 %%a && @%%a-%%b-%%c-%%d /x:.\%%b /q)
pause
我自已改了一下,这个应该可以执行了,但是还是不完美啊!
因为hotfix.txt里的文件名有不规则的
20060606.WindowsXP-KB916595-x86-CHS.exe
20060608.WindowsXP-KB918439-x86-CHS.exe
20060612.WindowsXP-KB914389-x86-CHS.exe
20060612.WindowsXP-KB917953-x86-CHS.exe
20060613.WindowsXP-KB917344-x86-CHS.exe
20060710.WindowsXP-KB914388-x86-CHS.exe
20060807.WindowsXP-KB920670-x86-CHS.exe
20060807.WindowsXP-KB920683-x86-CHS.exe
20060911.WindowsXP-KB919007-x86-CHS.exe
20060911.WindowsXP-KB920685-x86-CHS.exe
20060911.WindowsXP-KB922582-x86-CHS.exe
20061009.WindowsXP-KB922819-x86-CHS.exe
20061009.WindowsXP-KB923191-x86-CHS.exe
20061009.WindowsXP-KB923414-x86-CHS.exe
20061009.WindowsXP-KB924496-x86-CHS.exe
20061113.WindowsXP-KB920213-x86-CHS.exe
20061113.WindowsXP-KB923980-x86-CHS.exe
20061113.WindowsXP-KB924270-x86-CHS.exe
20061211.WindowsXP-KB926255-x86-CHS.exe
20070212.WindowsXP-KB918118-x86-CHS.exe
20070212.WindowsXP-KB924667-x86-CHS.exe
20070212.WindowsXP-KB926436-x86-CHS.exe
20070212.WindowsXP-KB927779-x86-CHS.exe
20070212.WindowsXP-KB927802-x86-CHS.exe
20070212.WindowsXP-KB928255-x86-CHS.exe
20070212.WindowsXP-KB928843-x86-CHS.exe
20070403.WindowsXP-KB925902-x86-CHS.exe
20070409.WindowsXP-KB930178-x86-CHS.exe
20070409.WindowsXP-KB931261-x86-CHS.exe
20070409.WindowsXP-KB931784-x86-CHS.exe
20070409.WindowsXP-KB932168-x86-CHS.exe
20070424.WindowsXP-KB930916-x86-CHS.exe
20070611.WindowsXP-KB929123-x86-CHS.exe
20070611.WindowsXP-KB935839-x86-CHS.exe
20070611.WindowsXP-KB935840-x86-CHS.exe
20070611.WindowsXP-KB936357-x86-CHS.exe
20070724.WindowsXP-KB938828-x86-CHS.exe
20070801.WindowsXP-KB933360-x86-CHS.exe
20070808.WindowsXP-KB896423-x86-CHS.exe
20070813.WindowsXP-KB938127-x86-CHS.exe
20070814.WindowsXP-KB921503-x86-CHS.exe
20070814.WindowsXP-KB936021-x86-CHS.exe
20070814.WindowsXP-KB938829-x86-CHS.exe
20071008.WindowsXP-KB933729-x86-CHS.exe
20071008.WindowsXP-KB941202-x86-CHS.exe
20071009.WindowsXP-KB939653-x86-CHS.exe
WindowsMedia9-KB936782-x86-CHS.exe
WindowsMedia10-KB936782-x86-CHS.exe
WindowsMedia11-KB936782-x86-CHS.exe
WindowsMedia11-KB939683-x86-CHS.exe
WindowsMedia11-KB929399-v2-x86-INTL.exe
20070813.IE7-WindowsXP-KB938127-x86-CHS.exe
20071009.IE7-WindowsXP-KB939653-x86-CHS.exe
20051213.WindowsXP-KB904706-v2-x86-CHS.exe
20060213.WindowsMedia-KB911564-x86-CHS.exe
20060425.WindowsXP-KB908531-v2-x86-CHS.exe
20060627.WindowsXP-KB911280-v2-x86-CHS.exe
20061113.WindowsXP-KB923789-x86-CHS.exe
20070507.WindowsXP-KB927891-v3-x86-CHS.exe
20070710.WindowsMedia6-KB925398-v2-x86-CHS.exe
20070710.WindowsXP-KB923689-v2-x86-CHS.exe
Windows-KB890830-V1.34.exe
KB939653.exe
但有一个共同点,就是包含kb******
dir /b |find "KB" >hotfix.txt
for /f "tokens=1-4 delims=-" %%a in (hotfix.txt) do @echo 正在提取 Windows XP 更新 %%a && @%%a-%%b-%%c-%%d /x:.\%%b /q)
pause
I modified it myself, this should be executable, but it's still not perfect!
Because the file names in hotfix.txt are irregular
20060606.WindowsXP-KB916595-x86-CHS.exe
20060608.WindowsXP-KB918439-x86-CHS.exe
20060612.WindowsXP-KB914389-x86-CHS.exe
20060612.WindowsXP-KB917953-x86-CHS.exe
20060613.WindowsXP-KB917344-x86-CHS.exe
20060710.WindowsXP-KB914388-x86-CHS.exe
20060807.WindowsXP-KB920670-x86-CHS.exe
20060807.WindowsXP-KB920683-x86-CHS.exe
20060911.WindowsXP-KB919007-x86-CHS.exe
20060911.WindowsXP-KB920685-x86-CHS.exe
20060911.WindowsXP-KB922582-x86-CHS.exe
20061009.WindowsXP-KB922819-x86-CHS.exe
20061009.WindowsXP-KB923191-x86-CHS.exe
20061009.WindowsXP-KB923414-x86-CHS.exe
20061009.WindowsXP-KB924496-x86-CHS.exe
20061113.WindowsXP-KB920213-x86-CHS.exe
20061113.WindowsXP-KB923980-x86-CHS.exe
20061113.WindowsXP-KB924270-x86-CHS.exe
20061211.WindowsXP-KB926255-x86-CHS.exe
20070212.WindowsXP-KB918118-x86-CHS.exe
20070212.WindowsXP-KB924667-x86-CHS.exe
20070212.WindowsXP-KB926436-x86-CHS.exe
20070212.WindowsXP-KB927779-x86-CHS.exe
20070212.WindowsXP-KB927802-x86-CHS.exe
20070212.WindowsXP-KB928255-x86-CHS.exe
20070212.WindowsXP-KB928843-x86-CHS.exe
20070403.WindowsXP-KB925902-x86-CHS.exe
20070409.WindowsXP-KB930178-x86-CHS.exe
20070409.WindowsXP-KB931261-x86-CHS.exe
20070409.WindowsXP-KB931784-x86-CHS.exe
20070409.WindowsXP-KB932168-x86-CHS.exe
20070424.WindowsXP-KB930916-x86-CHS.exe
20070611.WindowsXP-KB929123-x86-CHS.exe
20070611.WindowsXP-KB935839-x86-CHS.exe
20070611.WindowsXP-KB935840-x86-CHS.exe
20070611.WindowsXP-KB936357-x86-CHS.exe
20070724.WindowsXP-KB938828-x86-CHS.exe
20070801.WindowsXP-KB933360-x86-CHS.exe
20070808.WindowsXP-KB896423-x86-CHS.exe
20070813.WindowsXP-KB938127-x86-CHS.exe
20070814.WindowsXP-KB921503-x86-CHS.exe
20070814.WindowsXP-KB936021-x86-CHS.exe
20070814.WindowsXP-KB938829-x86-CHS.exe
20071008.WindowsXP-KB933729-x86-CHS.exe
20071008.WindowsXP-KB941202-x86-CHS.exe
20071009.WindowsXP-KB939653-x86-CHS.exe
WindowsMedia9-KB936782-x86-CHS.exe
WindowsMedia10-KB936782-x86-CHS.exe
WindowsMedia11-KB936782-x86-CHS.exe
WindowsMedia11-KB939683-x86-CHS.exe
WindowsMedia11-KB929399-v2-x86-INTL.exe
20070813.IE7-WindowsXP-KB938127-x86-CHS.exe
20071009.IE7-WindowsXP-KB939653-x86-CHS.exe
20051213.WindowsXP-KB904706-v2-x86-CHS.exe
20060213.WindowsMedia-KB911564-x86-CHS.exe
20060425.WindowsXP-KB908531-v2-x86-CHS.exe
20060627.WindowsXP-KB911280-v2-x86-CHS.exe
20061113.WindowsXP-KB923789-x86-CHS.exe
20070507.WindowsXP-KB927891-v3-x86-CHS.exe
20070710.WindowsMedia6-KB925398-v2-x86-CHS.exe
20070710.WindowsXP-KB923689-v2-x86-CHS.exe
Windows-KB890830-V1.34.exe
KB939653.exe
But there is a common point, that is, it contains kb******
|
|
2007-10-20 15:34 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 5 楼』:
用sed试试
使用 LLM 解释/回答一下
sed "s/.*KB\(\+\).*/& \/x:.\\KB\1/" hotfix.txt
sed "s/.*KB\(\+\).*/& \/x:.\\KB\1/" hotfix.txt
|
|
2007-10-20 15:46 |
|
|
26933062
银牌会员
    
积分 2268
发帖 879
注册 2006-12-19
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in ("!var!") do (
echo %%a x:.\%%b
))
pause
```
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in ("!var!") do (
echo %%a x:.\%%b
))
pause
```
|

致精致简! |
|
2007-10-20 15:49 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
@echo off
for /f "tokens=2 delims=B" %%a in (hotfix.txt) do (
for /f "delims=.-" %%i in ("%%a") do @echo 正在提取 Windows XP 更新 %%i
)
pause
@echo off
for /f "tokens=2 delims=B" %%a in (hotfix.txt) do (
for /f "delims=.-" %%i in ("%%a") do @echo Extracting Windows XP update %%i
)
pause
|
|
2007-10-20 16:08 |
|
|
zerocq
中级用户
  
积分 458
发帖 196
注册 2006-10-5
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
set test=20041119.WindowsXP-KB886677-x86-chs.exe
for /f "tokens=1-5 delims=KB-." %a in ('echo %test%') do @echo KB%b
set test=20041119.WindowsXP-KB886677-x86-chs.exe
for /f "tokens=1-5 delims=KB-." %a in ('echo %test%') do @echo KB%b
|
|
2007-10-20 19:30 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by 26933062 at 2007-10-20 03:49 PM:
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." ...
不能执行,且目录没有KB显示
Originally posted by 26933062 at 2007-10-20 03:49 PM:
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." ...
Cannot be executed, and there is no KB display in the directory
|
|
2007-10-21 11:30 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
Originally posted by slore at 2007-10-20 04:08 PM:
@echo off
for /f "tokens=2 delims=B" %%a in (hotfix.txt) do (
for /f "delims=.-" %%i in ("%%a") do @echo 正在提取 Windows XP 更新 %%i
)
pause
只是显示屏幕语句,没有实际操作,也不能显示KB******,只是将后面的数字提取出来了
Originally posted by slore at 2007-10-20 04:08 PM:
@echo off
for /f "tokens=2 delims=B" %%a in (hotfix.txt) do (
for /f "delims=.-" %%i in ("%%a") do @echo 正在提取 Windows XP 更新 %%i
)
pause
It's just a display screen statement, no actual operation, and it can't display KB******, just extracts the following numbers
|
|
2007-10-21 11:33 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
结合朋友们的帮助,我修改一下,下面的可以执行了
dir /b |find "KB" >hotfix.txt
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in ("!var!") do (
@echo 正在提取 Windows XP 更新 %%a && @%%a /x:.\%%b /q
))
pause
但是还有个小问题,提取的目录名称是KB后面的数字,KB两个字符没有
运行的效果如下:
20041119.WindowsXP-KB886677-x86-chs.exe /x:.\886677
20041213.WindowsXP-KB873339-x86-CHS.exe /x:.\873339
windowsmedia-KB885836-x86-CHS.exe /x:.\885836
Windows-KB890830-V1.34.exe /x:.\890830
KB939653.exe /x:.\939653
Last edited by nghr on 2007-10-21 at 11:57 AM ]
Combined with the help of friends, I modified it, and the following can be executed:
dir /b |find "KB" >hotfix.txt
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in ("!var!") do (
@echo Extracting Windows XP update %%a && @%%a /x:.\%%b /q
))
pause
But there is still a small problem. The extracted directory name is the number after KB, and the two characters KB are not there.
The running effect is as follows:
20041119.WindowsXP-KB886677-x86-chs.exe /x:.\886677
20041213.WindowsXP-KB873339-x86-CHS.exe /x:.\873339
windowsmedia-KB885836-x86-CHS.exe /x:.\885836
Windows-KB890830-V1.34.exe /x:.\890830
KB939653.exe /x:.\939653
Last edited by nghr on 2007-10-21 at 11:57 AM ]
|
|
2007-10-21 11:50 |
|
|
fastslz
铂金会员
       DOS一根葱
积分 5493
发帖 2315
注册 2006-5-1 来自 上海
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in ("!var!") do (
echo %%a x:.\KB%%b
))
pause
6楼的代码加%%b前面加KB,要实际操作echo %%a x:.\KB%%b里的echo去掉
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in ("!var!") do (
x:.\KB%%b
))
pause
|

第一高手 第二高手
我的小站
 |
|
2007-10-21 12:05 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
Originally posted by fastslz at 2007-10-21 12:05 PM:
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in (&q ...
感谢老兄,终于搞掂了!!!
Originally posted by fastslz at 2007-10-21 12:05 PM:
@echo off
setlocal EnableDelayedExpansion
for /f "delims=" %%a in (hotfix.txt) do (
set var=%%a
set var=!var:kb=#!
set var=!var:*#=!
for /f "tokens=1 delims=-." %%b in (&q ...
Thanks, buddy, finally got it done!!!
|
|
2007-10-21 12:09 |
|
|
nghr
初级用户
 
积分 88
发帖 34
注册 2007-10-20
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
再问一下各位老大
执行了上面的批处理之后,提取的KB*****目录下的文件结构如下:
update-----------------<目录
sp1qfe-----------------<目录
spuninst.exe---------<文件
spmsg.dll--------------<文件
sp2qfe-----------------<目录
而我要做的操作如下:
update-----------------<目录 ---------<操作:保留目录
sp1qfe-----------------<目录 ---------<操作:删除目录
spuninst.exe---------<文件 ---------<操作:删除文件
spmsg.dll--------------<文件 ---------<操作:删除文件
sp2qfe-----------------<目录 ---------<操作:保留目录
上面是大致要做的内容,当然不是DEL可以简单解决的,因为提取的目录是不规则的,有的还有其他目录,但有一个共同特点,就是每个KB******目录下都是有update与sp2qfe目录,我现在要做的具体操作就是删除kb******目录下所有文件与目录,只保留update与sp2qfe目录,请帮助指点一下
Let me see. The user is asking for help with batch processing to delete all files and directories under the KB***** directory except for the update and sp2qfe directories. The translated text would be:
Then ask you all bosses again
After executing the above batch processing, the file structure under the extracted KB***** directory is as follows:
update-----------------<Directory
sp1qfe-----------------<Directory
spuninst.exe---------<File
spmsg.dll--------------<File
sp2qfe-----------------<Directory
And the operations I need to do are as follows:
update-----------------<Directory ---------<Operation: Keep the directory
sp1qfe-----------------<Directory ---------<Operation: Delete the directory
spuninst.exe---------<File ---------<Operation: Delete the file
spmsg.dll--------------<File ---------<Operation: Delete the file
sp2qfe-----------------<Directory ---------<Operation: Keep the directory
The above is the general content to be done. Of course, it can't be simply solved by DEL, because the extracted directories are irregular, and there are other directories sometimes, but there is a common feature that is, under each KB****** directory there are update and sp2qfe directories. Now the specific operation I need to do is to delete all files and directories under the kb****** directory, only keep the update and sp2qfe directories. Please help to give pointers
|
|
2007-10-21 12:17 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by nghr at 2007-10-21 11:33:
只是显示屏幕语句,没有实际操作,也不能显示KB******,只是将后面的数字提取出来了
最难的就是提取数字吧?你自己不会改?汗~
Originally posted by nghr at 2007-10-21 11:33:
It's just a screen statement, no actual operation, and KB****** cannot be displayed, only the number behind is extracted
The most difficult thing is to extract the number? Can't you modify it yourself? Sweat~
|
|
2007-10-21 12:17 |
|