标题: 如何用FOR获取最后一个字符串
[打印本页]
作者: b102588
时间: 2007-8-20 10:11
标题: 如何用FOR获取最后一个字符串
请问用FOR 怎么得到最后一个字符啊
比如 d:\n\24 要得到24 N是变量
作者: akin520
时间: 2007-8-20 11:25
将文件夹名复制到1.txt
for /f "tokens=3* delims=:\" %a in (1.txt) do echo %a
[
Last edited by akin520 on 2007-8-20 at 11:31 AM ]
作者: Climbing
时间: 2007-8-20 14:57
楼上的方法恐怕是不行的,可能需要用到shift命令。
作者: akin520
时间: 2007-8-20 15:07
楼上,,SHIFT怎么用,,指点一下,,新手,不懂!
作者: b102588
时间: 2007-8-20 22:33
恩,我也想知道啊
作者: b102588
时间: 2007-8-20 22:36
还有2楼的不行啊,我说了中间的N是变量,可以有多成路径的。所以说不能这样获得最后一个字符。。
作者: Climbing
时间: 2007-8-21 08:09
@echo off & setlocal
set mypath=%1
set orgpath=%1
if [%mypath%]==[] goto :eof
set mypath=%mypath::= %
set mypath=%mypath:\= %
set thelast=
call :_getlast %mypath%
echo The Original is [%orgpath%].
echo The Last Part is [%thelast%].
endlocal
goto :eof
:_getlast
:_loop
if [%1]==[] goto :eof
set thelast=%1
shift
goto _loop
作者: Climbing
时间: 2007-8-21 08:10
当然,我的答案中已经无法用for了。这个问题我想不出用for来解决的方案。
作者: b102588
时间: 2007-8-21 09:53
set /p var1=请输入正确的路径及文件名:
ren %var1% 文件名.{21EC2020-3AEA-1069-A2DD-08002B30309D}
我的愿意是把文件伪装成控制面板,只要在文件名后加上.{21EC2020-3AEA-1069-A2DD-08002B30309D}
可是我不能获得这个文件名,所以就上论坛来问问。。。
不过现在好象变的好复杂啊,请问就我上面的目的有没什么简单的方法(其实也可以要求用户先输入路径,在输入一个文件名,用两次SET /P)
作者: Climbing
时间: 2007-8-21 11:46
这好象很简单啊。
@echo off & setlocal
set /p orgpath=请输入正确的路径及文件名:
set mypath=%orgpath%
if [%mypath%]==[] goto :eof
set mypath=%mypath::= %
set mypath=%mypath:\= %
set thelast=
call :_getlast %mypath%
ren %orgpath% %thelast%.{21EC2020-3AEA-1069-A2DD-08002B30309D}
endlocal
goto :eof
:_getlast
:_loop
if [%1]==[] goto :eof
set thelast=%1
shift
goto _loop
作者: b102588
时间: 2007-8-22 10:26
谢了哈。。