windows - Replace the part of the path by string in specific file type in a folder -
in u:\mtproject\obj\
folder , sub-folders having *.def
files. need file paths , print in command prompt. before print need replace u:\mtproject\obj\
part e:\backupdir\defbackup\
.
here tried ,
set objdir=u:\mtproject\obj\ set backupdir=e:\backupdir\defbackup\ /r %objdir% %%f in (*.def) ( set new_def_path = %backupdir%!%%f:%objdir%=! echo %new_def_path% )
it shows output. feel issue in syntax of string replacement. idea wrong?
echo off. echo off. echo off. echo off. echo off. echo off. echo off. echo off. echo off.
a) use delayed expanison (as somethingdark mentioned)
b) remove spaces whith set
commands or spaces part of variablename or value.
setlocal enabledelayedexpansion set objdir=u:\mtproject\obj\ set backupdir=e:\backupdir\defbackup\ /r %objdir% %%f in (*.def) ( set new_def_path=%backupdir%!%%f:%objdir%=! echo !new_def_path! )
short demonstration of delayed expansion trap
(interesting: use delayed expansion. consequent)
Comments
Post a Comment