|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『楼 主』:
如何获取路径最后一个"\"后的字串[完美解决]
使用 LLM 解释/回答一下
已解决,见http://www.cn-dos.net/forum/viewthread.php?tid=27658&page=1&sid=FB2nu4#pid174202 贴2楼ZH159兄的回答.
下面是我的代码,请修改
@ECHO OFF
SET PATH=%CD%;%CD%\TOOLS\;%PATH%
FOR /F "EOL=;DELIMS=" %%I in (.\Purge\PurgeS.SVE) DO (
ECHO 正在压缩备份%windir%\%%I\下的文件,请稍等......
PING 127.0.0.1 -n %TIMEOUT% >NUL
RAR.EXE A -EP3 -IDQ ".\BACKUP\%%I" "%windir%\%%I"
)
PAUSE
其中PurgeS.SVE中的内容如下:
;这里可以设置要备份和清理的系统级垃圾文件,必须以文件夹来表示,而且必须以%windir%为根来表示
;如果设置了字体清理,需要设置在FONTS.SVE中设置要保留的字体文件
;输入法清理请单独在IME.SVE中进行设置
;
;
;可备份和清理的文件夹,如果想保留则使用;注释掉要清理的项目;也可以添加其他需要备份和清理的文件夹中的内容如Web\Wallpaper下的墙纸
;字体
FONTS
;帮助
HELP
;帮助支持中心
PCHealth
;驱动缓存
Driver Cache
;DLL缓存
SYSTEM32\dllcache
;系统修复备份
REPAIR
;预存取
prefetch
;搜索助理
srchasst
;微软代理
msagent
;系统激活(只限于VOL版)
;system32\oobe
大家应该看明白了我这段代码的意思,我是使用RAR程序把PurgeS.SVE指定中指定的文件夹下的所有文件压缩备份到当前的BACKUP目录下,但是运行到有子目录的SYSTEM32\dllcache时则出现错误,提示找不到压缩文件要备份的路径,因为我是想不区分有无子目录一切都直接备份到BACKUP目录,而且并以目录的最后一个子目录的名称来确定压缩文件的名称,如SYSTEM32\dllcache备份后压缩文件应该是dllcache.rar 而且必须位于BACKUP目录下
希望大家给我一个解决的思路或代码,要求使用批处理,不使用VBS,运行环境为WINXP,谢谢.
有关RAR命令,我刚才把自己的学习笔记发到http://www.cn-dos.net/forum/viewthread.php?tid=27657&sid=FB2nu4 ,可以参考.
17楼出现新的问题,在线等待高手们的再次回答
Last edited by HUNRYBECKY on 2007-2-14 at 03:09 AM ]
Solved, see http://www.cn-dos.net/forum/viewthread.php?tid=27658&page=1&sid=FB2nu4#pid174202 Post 2 building ZH159 brother's answer.
Below is my code, please modify
@ECHO OFF
SET PATH=%CD%;%CD%\TOOLS\;%PATH%
FOR /F "EOL=;DELIMS=" %%I in (.\Purge\PurgeS.SVE) DO (
ECHO Compressing and backing up files under %windir%\%%I\, please wait...
PING 127.0.0.1 -n %TIMEOUT% >NUL
RAR.EXE A -EP3 -IDQ ".\BACKUP\%%~nI" "%windir%\%%I"
)
PAUSE
The content in PurgeS.SVE is as follows:
; Here you can set the system-level garbage files to be backed up and cleaned. They must be represented by folders and must be represented with %windir% as the root.
; If font cleaning is set, you need to set the font files to be retained in FONTS.SVE.
; Input method cleaning should be carried out separately in IME.SVE.
;
;
; Folders that can be backed up and cleaned. If you want to retain them, use ; to comment out the items to be cleaned; you can also add the contents of other folders that need to be backed up and cleaned, such as the wallpapers under Web\Wallpaper
; Fonts
FONTS
; Help
HELP
; Help support center
PCHealth
; Driver cache
Driver Cache
; DLL cache
SYSTEM32\dllcache
; System repair backup
REPAIR
; Prefetch
prefetch
; Search assistant
srchasst
; Microsoft Agent
msagent
; System activation (only for VOL version)
; system32\oobe
Everyone should have understood the meaning of my code. I am using the RAR program to compress and back up all the files in the folder specified in PurgeS.SVE to the current BACKUP directory. But when running to SYSTEM32\dllcache with subdirectories, an error occurs, prompting that the path of the compressed file to be backed up is not found. Because I want to back up directly to the BACKUP directory regardless of whether there are subdirectories, and determine the name of the compressed file with the name of the last subdirectory of the directory. For example, the backup of SYSTEM32\dllcache should be dllcache.rar and must be in the BACKUP directory.
I hope everyone can give me a solution idea or code. It is required to use batch processing, not use VBS, and the running environment is WINXP. Thank you.
Regarding the RAR command, I just sent my study notes to http://www.cn-dos.net/forum/viewthread.php?tid=27657&sid=FB2nu4, which can be referred to.
There is a new problem in building 17, waiting online for the masters' answer again
Last edited by HUNRYBECKY on 2007-2-14 at 03:09 AM ]
|
|
2007-2-13 02:45 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
dim Str1,Pos
Str1="C:\WINDOWS\IME\CINTLGNT"
Pos=InstrRev(Str1,"\")
msgbox mid(Str1,Pos+1,len(Str1)-Pos)
### Step 1: Analyze the code
- `Str1 = "C:\WINDOWS\IME\CINTLGNT"`: This is a string variable assigned a path.
- `Pos = InstrRev(Str1, "\")`: `InstrRev` is a function to find the last occurrence of a character in a string. Here, it finds the last backslash in `Str1`.
- `mid(Str1, Pos + 1, len(Str1) - Pos)`: `Mid` function is used to extract a substring. It starts from the position after the last backslash and takes the remaining characters.
### Step 2: Translate the code's functionality description (since the code itself is in English-like structure but we need to ensure correct translation of the logic description)
The code first defines a string `Str1` with a path, then finds the position of the last backslash in `Str1`, and then extracts the substring starting from the character after the last backslash.
In terms of the final result, the code will extract the last part of the path after the last backslash. The translated code execution result is that the message box will display "CINTLGNT".
But according to the requirements, we just translate the original text as per the rules. The original code is in a programming language (VBScript like), and when translating the content:
The code lines are:
```vb
dim Str1,Pos
Str1="C:\WINDOWS\IME\CINTLGNT"
Pos=InstrRev(Str1,"\")
msgbox mid(Str1,Pos+1,len(Str1)-Pos)
```
Translated:
```vb
dim Str1, Pos
Str1 = "C:\WINDOWS\IME\CINTLGNT"
Pos = InstrRev(Str1, "\")
msgbox Mid(Str1, Pos + 1, Len(Str1) - Pos)
```
The result of running this code is to display "CINTLGNT" in the message box. But following the instruction to just provide the translated text as per the input, the translated code is as above, and the result of the code is "CINTLGNT". So the final output related to the translation of the code content is:
```vb
dim Str1, Pos
Str1 = "C:\WINDOWS\IME\CINTLGNT"
Pos = InstrRev(Str1, "\")
msgbox Mid(Str1, Pos + 1, Len(Str1) - Pos)
```
And the actual value shown in the message box is "CINTLGNT"
|
|
2007-2-13 02:49 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
Originally posted by slore at 2007-2-13 02:49:
dim Str1,Pos
Str1="C:\WINDOWS\IME\CINTLGNT"
Pos=InstrRev(Str1,"\")
msgbox mid(Str1,Pos+1,len(Str1)-Pos)
谢谢回答,我想使用批处理,不使用VBS
Originally posted by slore at 2007-2-13 02:49:
dim Str1,Pos
Str1="C:\WINDOWS\IME\CINTLGNT"
Pos=InstrRev(Str1,"\")
msgbox mid(Str1,Pos+1,len(Str1)-Pos)
Thanks for the answer, I want to use batch processing, not VBS
|
|
2007-2-13 02:58 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
for /f "tokens=*" %? in ('dir /ad/b c:\') do (echo %?|sed -r "s/.*\\([^\]*)$/\1/")
for /f "tokens=*" %? in ('dir /ad/b c:\') do (echo %?|sed -r "s/.*\\(*)$/\1/")
|
|
2007-2-13 03:00 |
|
|
redtek
金牌会员
     
积分 2902
发帖 1147
注册 2006-9-21
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
获取路径最后一个"\"后的字串原理:)
FOR /?
%~nI - 仅将 %I 扩展到一个文件名
### Principle of getting the substring after the last "\" in the path :)
FOR /?
%~nI - Expand %I to a file name only
|

Redtek,一个永远在网上流浪的人……
_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._ |
|
2007-2-13 03:01 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
Originally posted by vkill at 2007-2-13 03:00:
for /f "tokens=*" %? in ('dir /ad/b c:\') do (echo %?|sed -r "s/.*\\(*)$/\1/")
我不想使用SED这个东西,谢谢VKILL兄弟的回答,有其他方法吗?
Originally posted by vkill at 2007-2-13 03:00:
for /f "tokens=*" %? in ('dir /ad/b c:\') do (echo %?|sed -r "s/.*\\(*)$/\1/")
I don't want to use SED, thank you Brother VKILL for your answer. Is there any other way?
|
|
2007-2-13 03:09 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
Originally posted by redtek at 2007-2-13 03:01:
获取路径最后一个"\"后的字串原理:)
FOR /?
谢谢REDTEK兄的回答,但是我如下使用,好象不对,能否修改下.
@ECHO OFF
SET PATH=%CD%;%CD%\TOOLS\;%PATH%
FOR /F "EOL=;DELIMS=" %%I in (.\Purge\PurgeS.SVE) DO (
ECHO 正在压缩备份%windir%\%%I\下的文件,请稍等......
PING 127.0.0.1 -n %TIMEOUT% >NUL
RAR.EXE A -EP3 -IDQ ".\BACKUP\%%I:%~nI" "%windir%\%%I"
)
PAUSE
### Re: 获取路径最后一个"\"后的字串原理:)
Thanks for REDTEK brother's answer, but I use it as follows, it seems wrong, can you modify it.
@ECHO OFF
SET PATH=%CD%;%CD%\TOOLS\;%PATH%
FOR /F "EOL=;DELIMS=" %%I in (.\Purge\PurgeS.SVE) DO (
ECHO Compressing and backing up files under %windir%\%%I\, please wait a moment......
PING 127.0.0.1 -n %TIMEOUT% >NUL
RAR.EXE A -EP3 -IDQ ".\BACKUP\%%I:%~nI" "%windir%\%%I"
)
PAUSE
|
|
2007-2-13 03:15 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
@echo off
FOR /F "EOL=;DELIMS=" %%I in (PurgeS.SVE) DO (
ECHO 正在压缩备份%windir%\%%I\下的文件,请稍等......
PING 127.0.0.1 -n %TIMEOUT% >NUL
for /F "tokens=2 DELIMS=\" %%J IN ("%%I") do echo ".\BACKUP\%%J" "%windir%\%%I"
echo ".\BACKUP\%%I" "%windir%\%%I"
)
PAUSE
@echo off
FOR /F "EOL=;DELIMS=" %%I in (PurgeS.SVE) DO (
ECHO Compressing and backing up files under %windir%\%%I\, please wait...
PING 127.0.0.1 -n %TIMEOUT% >NUL
for /F "tokens=2 DELIMS=\" %%J IN ("%%I") do echo ".\BACKUP\%%J" "%windir%\%%I"
echo ".\BACKUP\%%I" "%windir%\%%I"
)
PAUSE
|
|
2007-2-13 03:28 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Originally posted by slore at 2007-2-13 03:28:
@echo off
FOR /F "EOL=;DELIMS=" %%I in (PurgeS.SVE) DO (
ECHO 正在压缩备份%windir%\%%I\下的文件,请稍等......
PING 127.0.0.1 -n %TIMEOUT% >NUL
for /F "tok ...
再次谢谢兄的回答,不过因为路径的层数不是固定的,所以使用你的这个方法还是不行,你这个DELIMES=2只有2层,如果是3层,4层呢?
再说明下我获取以\的目录的最后的名称的原因在于我便于使用RAR命令重新恢复,如我备份了所有项目,那么可以让用户选择要恢复的内容,如日文输入法,韩文输入法,MS拼音输入法等,如果整体直接压缩到一个或某个包内,恢复时使用RAR命令是很不方便的
Last edited by HUNRYBECKY on 2007-2-13 at 03:53 AM ]
Originally posted by slore at 2007-2-13 03:28:
@echo off
FOR /F "EOL=;DELIMS=" %%I in (PurgeS.SVE) DO (
ECHO Compressing and backing up files under %windir%\%%I\, please wait...
PING 127.0.0.1 -n %TIMEOUT% >NUL
for /F "tok ...
Thanks brother again for the answer, but because the number of path levels is not fixed, so using your this method still doesn't work. Your this DELIMES=2 only has 2 levels. What if there are 3 levels, 4 levels?
Let me explain again the reason why I get the last name of the directory with \ is that it is convenient for me to use the RAR command to restore again. For example, if I have backed up all items, then I can let the user choose the content to restore, such as Japanese input method, Korean input method, MS Pinyin input method, etc. If it is directly compressed into one or a certain package as a whole, it is very inconvenient to use the RAR command for restoration
Last edited by HUNRYBECKY on 2007-2-13 at 03:53 AM ]
|
|
2007-2-13 03:50 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
依然在线等待..................期待高手们的回答.
Still waiting online..................Looking forward to the answers from the experts.
|
|
2007-2-13 04:03 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 11 楼』:
[在线求助]如何处理这样的路径字符串[已结]
使用 LLM 解释/回答一下
─────────────────── 版务记录 ────────────────────
执行:namejm
说明:{tid=27658}与本主题存在上下文关系,合并到本主题下。
处罚:因该用户在论坛里并非新人,理应对本论坛的发帖规定有所了解,故扣除
该用户发帖所得的4点积分。
─────────────────── 版务记录 ────────────────────
C:\WINDOWS\system32
C:\WINDOWS\SHELLNEW
C:\WINDOWS\system32\dhcp
C:\WINDOWS\system32\dllcache
C:\WINDOWS\Help\Tours\mmTour
C:\WINDOWS\Help\Tours\WindowsMediaPlayer
C:\WINDOWS\ime\CHSIME
C:\WINDOWS\ime\SHARED
上面这些路径中,我只想获取路径中最后一个\的内容,如得到的结果如下
system32
SHELLNEW
dhcp
dllcache
mmTour
WindowsMediaPlayer
CHSIME
SHARED
请求高手们给点意见,要求不使用第三方工具,不使用VBS脚本
Last edited by namejm on 2007-2-12 at 04:46 PM ]
─────────────────── Moderation Record ────────────────────
Performer: namejm
Description: {tid=27658}has contextual relationship with this topic, merged into this topic.
Punishment: Since the user is not a new user in the forum, they should be aware of the forum's posting regulations. Therefore, 4 points of points earned from the user's posts are deducted.
─────────────────── Moderation Record ────────────────────
C:\WINDOWS\system32
C:\WINDOWS\SHELLNEW
C:\WINDOWS\system32\dhcp
C:\WINDOWS\system32\dllcache
C:\WINDOWS\Help\Tours\mmTour
C:\WINDOWS\Help\Tours\WindowsMediaPlayer
C:\WINDOWS\ime\CHSIME
C:\WINDOWS\ime\SHARED
Among these paths above, I only want to get the content after the last \ in the path, such as the results obtained as follows
system32
SHELLNEW
dhcp
dllcache
mmTour
WindowsMediaPlayer
CHSIME
SHARED
Please ask experts for some suggestions. It is required not to use third - party tools and not to use VBS scripts
Last edited by namejm on 2007-2-12 at 04:46 PM ]
|
|
2007-2-13 04:20 |
|
|
zh159
金牌会员
     
积分 3687
发帖 1467
注册 2005-8-8
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
list.txt
C:\WINDOWS\system32
C:\WINDOWS\SHELLNEW
C:\WINDOWS\system32\dhcp
C:\WINDOWS\system32\dllcache
C:\WINDOWS\Help\Tours\mmTour
C:\WINDOWS\Help\Tours\WindowsMediaPlayer
C:\WINDOWS\ime\CHSIME
C:\WINDOWS\ime\SHARED
@echo off
for /f "delims=" %%i in (list.txt) do echo %%~ni
pause
list.txt
C:\WINDOWS\system32
C:\WINDOWS\SHELLNEW
C:\WINDOWS\system32\dhcp
C:\WINDOWS\system32\dllcache
C:\WINDOWS\Help\Tours\mmTour
C:\WINDOWS\Help\Tours\WindowsMediaPlayer
C:\WINDOWS\ime\CHSIME
C:\WINDOWS\ime\SHARED
@echo off
for /f "delims=" %%i in (list.txt) do echo %%~ni
pause
|
|
2007-2-13 04:42 |
|
|
HUNRYBECKY
银牌会员
    
积分 1179
发帖 442
注册 2006-9-9
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
非常感谢zh159兄对我的问题多次回答,得向你好好学习.
刚才redtek兄也回答了我这个问题,本人因为对FOR语句实在用的不熟悉,所以还是没有明白redtek兄的意思,我居然当作SET的变量来处理,搞成%%I:%~nI,所以怎么搞都不出来.
再次非常感谢兄的回答.
I'm very grateful to Brother zh159 for answering my question many times. I should learn from you a lot.
Just now, Brother redtek also answered my question. Because I'm not familiar with the FOR statement at all, I still didn't understand Brother redtek's meaning. I actually treated it as a SET variable and made it %%I:%~nI, so no matter how I did it, it didn't come out.
Thank you again for your answer.
|
|
2007-2-13 05:08 |
|
|
slore
铂金会员
      
积分 5212
发帖 2478
注册 2007-2-8
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
同时感谢~
对bat里的for还差好多呀..
Also thank you~
Still a lot to go with the for in bat..
|
|
2007-2-13 05:16 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
哎,竟然忘记了用%~ni
Hey, I actually forgot to use %~ni
|
|
2007-2-13 06:03 |
|
|