The topic of this issue: Extraction of the last name in the directory
Because the names of any directories are different. But they all meet the format of
c:\aaa\bbb\ccc
So our requirement is to extract ccc.
This format can be obtained through dir /b /s /ad.
VBS can be used for extraction
But third-party tools are not allowed...............
Challenge keywords: set /a, variable delay, if not defined
Not allowed: special parameters when using for or call, such as %~nxi and so on.
[ Last edited by flyinspace on 2007-4-30 at 05:03 PM ]
Because the names of any directories are different. But they all meet the format of
c:\aaa\bbb\ccc
So our requirement is to extract ccc.
This format can be obtained through dir /b /s /ad.
VBS can be used for extraction
But third-party tools are not allowed...............
Challenge keywords: set /a, variable delay, if not defined
Not allowed: special parameters when using for or call, such as %~nxi and so on.
set "aaa=c:\windows\system32\playuo\cndos\asd adf"
set /a "count=0","count1=0"
set "FileName="
for /f "tokens=* " %%i in ("%aaa%") do (
set str=%%~i
for /l %%a in (0,1,255) do if "!str:~%%a,1!"=="" if not defined len set len=%%a
for /l %%a in (0,1,255) do if "!str:~%%a,1!"=="\" set /a count+=1
for /l %%a in (0,1,255) do (
set abc=!str:~%%a,1!
if "!count!"=="!count1!" (
set /a "lenflag=!len!-%%a"
if not defined FileName call :GetName "!lenflag!" "%%a"
)
if "!abc!"=="\" set /a count1=!count1!+1
)
echo In the %aaa% directory
echo The extracted folder name is: "!FileName!"
)
goto :END
:GetName _len_ _len_
set "parm1=%~1"
set "parm2=%~2"
set "FileName=!str:~%parm2%,%parm1%!
goto :EOF
:END
pause
[ Last edited by flyinspace on 2007-4-30 at 05:03 PM ]
Recent Ratings for This Post
( 1 in total)
Click for details
| Rater | Score | Time |
|---|---|---|
| youxi01 | +8 | 2007-04-30 13:31 |
知,不觉多。不知,乃求知
