![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-06 09:25 |
48,039 topics / 350,124 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » [Solved] How to get n characters starting from a specified character in a string |
| Printable Version 3,268 / 18 |
| Floor1 nghr | Posted 2007-10-20 14:32 |
| 初级用户 Posts 34 Credits 88 | |
|
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 ] |
|
| Floor2 junchen2 | Posted 2007-10-20 15:04 |
| 高级用户 Posts 219 Credits 537 From 杭州--半山 | |
|
@echo off
@for /f "tokens=1-4 delims=-" %%a in (hotfix.txt) do echo %%a-%%b-%%c-%%d /x:.\%%b pause |
|
| Floor3 nghr | Posted 2007-10-20 15:28 |
| 初级用户 Posts 34 Credits 88 | |
|
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 ] |
|
| Floor4 nghr | Posted 2007-10-20 15:34 |
| 初级用户 Posts 34 Credits 88 | |
|
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****** |
|
| Floor5 lxmxn | Posted 2007-10-20 15:46 |
| 版主 Posts 4,938 Credits 11,386 | |
| Floor6 26933062 | Posted 2007-10-20 15:49 |
| 银牌会员 Posts 879 Credits 2,268 | |
|
```
@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 ``` |
|
| Floor7 slore | Posted 2007-10-20 16:08 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
@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 |
|
| Floor8 zerocq | Posted 2007-10-20 19:30 |
| 中级用户 Posts 196 Credits 458 | |
|
set test=20041119.WindowsXP-KB886677-x86-chs.exe
for /f "tokens=1-5 delims=KB-." %a in ('echo %test%') do @echo KB%b |
|
| Floor9 nghr | Posted 2007-10-21 11:30 |
| 初级用户 Posts 34 Credits 88 | |
Originally posted by 26933062 at 2007-10-20 03:49 PM: |
|
| Floor10 nghr | Posted 2007-10-21 11:33 |
| 初级用户 Posts 34 Credits 88 | |
Originally posted by slore at 2007-10-20 04:08 PM: It's just a display screen statement, no actual operation, and it can't display KB******, just extracts the following numbers |
|
| Floor11 nghr | Posted 2007-10-21 11:50 |
| 初级用户 Posts 34 Credits 88 | |
|
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 ] |
|
| Floor12 fastslz | Posted 2007-10-21 12:05 |
| 铂金会员 Posts 2,315 Credits 5,493 From 上海 | |
|
@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 |
|
| Floor13 nghr | Posted 2007-10-21 12:09 |
| 初级用户 Posts 34 Credits 88 | |
Originally posted by fastslz at 2007-10-21 12:05 PM: Thanks, buddy, finally got it done!!! |
|
| Floor14 nghr | Posted 2007-10-21 12:17 |
| 初级用户 Posts 34 Credits 88 | |
|
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 |
|
| Floor15 slore | Posted 2007-10-21 12:17 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
Originally posted by nghr at 2007-10-21 11:33: The most difficult thing is to extract the number? Can't you modify it yourself? Sweat~ |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |