So this is basically what I'm trying to do,
remove the string stored in %DST% from the
string %fullname%.
set DST=c:\test\laptop
set relname=!fullname:!DST!=!If it is not possible to do this, then let me
explain why I'm trying to, and maybe it can be
approached from a different angle...I need to compare all the files in a destination
directory (and subdirectories) with those of a
source directory. If a file in the destination
does not exist in the source, delete it. Within
their respective root directories (%SRC% and
%DST%), the directory structures are
identical. I would like to keep the source and
destination root directories as variables so any
necessary changes will only have to be made
in one place in the file.This is what I currently have. It works only if I
type the literal DST string in the following:
set relname=!fullname:!DST!=!
I appreciate any help!@echo off
SETLOCAL ENABLEDELAYEDEXPANSIONset SRC=\\fox-server\data
set DST=c:\test\laptopFor /f "delims=" %%a in ('Dir /s /b %DST%')
do (
set fullname=%%a
set relname=!fullname:!DST!=!if not exist "!SRC!\!relname!" (
echo !DST!\!relname!
rmdir "!DST!\!relname!" /s /q
del "!DST!\!relname!" /q
)
)pause
@echo off & setLocal EnableDELAYedeXpansion set fullname=c:\test\laptop\bla
set DST=c:\test\laptop
set relname=!fullname:%DST%=!
echo.!relname!
=====================================
Helping others achieve escape felicityM2
since DST is assigned outside (prior to) the for-loop, you should be able to get away with:
set relname=!fullname:%DST%=!
another way:
for /f "tokens=1-3* delims=/" %%a in ('dir /b /s...
set dst=%%a/%%b/%%c/%%d
...
but that locks it in at third-level directory on the source.
To separate them out, try this: =============================
@echo off & setLocal EnableDELAYedeXpansionfor /f "tokens=* delims= " %%a in ('dir/b/s/a-d') do (
echo.%%~DPa
echo.%%~NXa
)
=====================================
Helping others achieve escape felicityM2
Yes (14) | ![]() | |
No (14) | ![]() | |
I don't know (15) | ![]() |