Back again after a serious lack of DOS practice.
Trying to do something in DOS that probably can be done way simpler (in DOS) than what I'm doing now/here.
The Target is to get a "Dir /b/s ... > file.log" output file that has some leading part of the paths removed.
Which part of the path should be removed is based on a given folder name.
Example: If we have the following folders.
Code: Select all
X:\aaa\bbb\xyz\cc1
X:\aaa\bbb\xyz\cc2\dd1
X:\aaa\bbb\xyz\cc3\dd2\ee1
The target result would be. (leading backslash not important.)
Code: Select all
\xyz\cc1
\xyz\cc2\dd1
\xyz\cc3\dd2\ee1
Seemed simple enough at first. ... But I ended up with this.
Its working ... but way to slow to be of any real use. (+1000 files) (assuming the maximum supported path length of 26 folders wringing the speed out of it)
Is there a better way I missed? (or better switch to a other language for this, like python)
Code: Select all
@echo off
setlocal enableDelayedExpansion
set "target=xyz"
::dir /b/s /a/a-d > out1.tmp
:: OR, (depending on how its used)
dir /b/s /a/a-d %target%\ > out1.tmp
echo.>out2.tmp
:: Set num to "1,2,..,26" for token use.
set "num=1" & FOR /L %%A IN (2,1,26) DO set "num=!num!,%%A"
set "A1="
for /F "delims=\ tokens=%num%" %%a in (out1.tmp) do (
setlocal enableDelayedExpansion
set "A1=" &rem - clear for new path.
for %%1 in (%%a %%b %%c %%d %%e %%f %%g %%h %%i %%j %%k %%l %%m %%n %%o %%p %%q %%r %%s %%t %%u %%v %%w %%x %%y %%z) do (
if not "%%1"=="" (
REM ~ echo.1=%%1
call:myFunc A1, "!A1!", "%%1", "!target!"
)
)
echo.A1=!A1!
REM ~ if not "!A1!"=="" echo.A1=!A1!&echo.!A1!>>out2.tmp
endlocal
)
goto:eof
:myFunc - out, in2, in3, in4 ... remark
SETLOCAL
set "out="
if "%~2"=="" (
if "%~3"=="%~4" set "out=\%~3"
) else (
set "out=%~2\%~3"
)
ENDLOCAL&set "%~1=%out%"
goto:eof