![]() |
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-11 08:49 |
47,811 topics / 349,897 posts / today 0 new / 48,256 members |
| DOS批处理 & 脚本技术(批处理室) » Help with two BAT problems, please help solve them, thanks |
| Printable Version 801 / 9 |
| Floor1 raythunder | Posted 2009-01-29 15:21 |
| 初级用户 Posts 30 Credits 47 | |
|
Moved from DOS Troubleshooting & Problem Discussion (Answer Room) Obviously posted in the wrong section. Although you're a forum newbie, you've been registered for over a year, so you should be somewhat familiar with the forum by now. A suitable point deduction is given as a reminder. ——Administrator I'm quite interested in BAT, so I often tinker with it. Now I've run into two problems. I've thought about them for a while but still couldn't solve them, so now I'd like to ask friends here who are proficient in BAT to help me out. The first problem is: I want to make a BAT to extract a path. This path is in the registry. As everyone knows, in registry files exported from the registry, paths are marked with double slashes ("\\") rather than single slashes ("\") . Let's use QQ's installation path as an example. Below is the first part of what I made to extract the path; I can't do the rest. @Echo off reg export HKEY_LOCAL_MACHINE\SOFTWARE\TENCENT\QQ\ 1.txt for /f "tokens=1* delims==" %%i in ('find /I "=" 1.txt') do echo %%j >2.txt If your QQ is installed under C:\program files\tencent\qq\ then what you get in 1.txt is this: Windows Registry Editor Version 5.00 "Install"="C:\\Program Files\\Tencent\\QQ\\" And what you get in 2.txt is: "C:\\Program Files\\Tencent\\QQ\\" But what I want now is to get it displayed in the form C:\Program Files\Tencent\QQ\ How should I do that? Of course, you don't have to start from these first two lines I made; you can use your own method entirely. As long as the result can be obtained in the form C:\Program Files\Tencent\QQ\ that's fine. I've tried the following method: @Echo off reg export HKEY_LOCAL_MACHINE\SOFTWARE\TENCENT\QQ\ 1.txt for /f "tokens=1* delims==" %%i in ('find /I "=" 1.txt') do echo %%j >2.txt set /a n=2 :loop set /a m=%n%+1 find /i "\\" %n%.txt >NUL if %errorlevel%==0 set /a n=%n%+1&& for /f "tokens=1* delims=\\" %%i in ('type %n%.txt') do echo %%i\%%j >%m%.txt&&goto loop But the result can only be "C:\Program Files\\Tencent\\QQ\\", and it goes into an endless loop. I hope friends here who are proficient in BAT can also point out what's wrong with the batch above. Many thanks. The first method was provided by Slore. Based on my original one, it uses the set function, a bit like renaming. It achieves the requirement with minimal changes. Solid. Thanks to Slore. Specifically as follows: The second method was provided by tireless. It improves my approach and does it in one step. Concise. Thanks to tireless The second problem is simpler to describe: I want to add serial numbers to every file in a folder. How should I do that? For example: suppose I have a folder MP3 under drive D, with many songs in it. Now I want to keep the song names unchanged, and only add serial numbers like 01, 02, 03... in front of the song names. How should I do that? For the second problem, friend Slore told me to search the forum, but I couldn't think of the right keywords. Then it turned out a friend had posted asking about merging two text files line by line. The address is here: http://www.cn-dos.net/forum/viewthread.php?tid=45985&fpage=4 A friend there came up with an answer, so I learned from it and solved my problem. Specifically as follows: [ Last edited by raythunder on 2009-2-9 at 15:21 ] |
|
| Floor2 raythunder | Posted 2009-01-31 15:34 |
| 初级用户 Posts 30 Credits 47 | |
|
It's been three days since I posted this. The view count is 41.
How come the experts still haven't finished celebrating the New Year and come online? Maybe this really wasn't a good time to post. I saw there was a problem discussion section and came in, but didn't expect I'd come to the wrong place. Thanks to Manager for setting it right!!! Still waiting for results. These days I'm at home, and getting online isn't convenient, but I'll come check the results every few days. If friends passing by could give this a bump, so the thread doesn't sink, I'd appreciate it. Still waiting for results... |
|
| Floor3 slore | Posted 2009-01-31 15:42 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
| Floor4 raythunder | Posted 2009-01-31 15:48 |
| 初级用户 Posts 30 Credits 47 | |
|
Thanks to Slore for replying.
The result is out now. I'd like to ask, how should this line be understood? set a=%a:\\=\% |
|
| Floor5 slore | Posted 2009-01-31 15:50 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Replace \\ with \
Take a good look at set /? . As for the renaming one, there are also many posts about it on the forum. Make good use of search. |
|
| Floor6 raythunder | Posted 2009-01-31 15:53 |
| 初级用户 Posts 30 Credits 47 | |
|
Many thanks to Slore for clearing that up.
Can the second problem be solved together as well? |
|
| Floor7 slore | Posted 2009-01-31 19:28 |
| 铂金会员 Posts 2,478 Credits 5,212 | |
|
Search the forum. There are lots of examples.
|
|
| Floor8 tireless | Posted 2009-01-31 23:08 |
| 银牌会员 Posts 1,122 Credits 2,025 | |
@Echo off This can change double slashes into single slashes. |
|
| Floor9 raythunder | Posted 2009-02-01 15:09 |
| 初级用户 Posts 30 Credits 47 | |
|
%~fI - expands %I to a fully qualified path name
Thanks to tireless for providing yet another new method. |
|
| Floor10 raythunder | Posted 2009-02-09 15:22 |
| 初级用户 Posts 30 Credits 47 | |
|
Thanks to all the friends here for the help, and thanks to the related forum posts for their help too.
TKS |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |