- How to perform string concatenation or find length of a string

  • Thread starter Thread starter Matthias Tacke
  • Start date Start date
M

Matthias Tacke

S>B>S said:
Here is the actual script
::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
set srcDir=c:\UPDATES
set trgDir=c:\APPFILES
set len=10

for /f "delims=" %%F in ('dir %srcDir% /A-D/B/S') do (
call :sub "%%~F"
)

goto :eof
:sub
set Name=%~1
set flName="%trg%%Name:~10%"
set Path=%~dp1

if exist %flName% (
psfile %flName% -c
)
copy "%Name%" "%trg%%Path:~10%"
::::::::::::::::::::::::::::::::::::::::::::
Simply exchange the src path with target path using set.

::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal EnableDelayedExpansion
set srcDir=c:\UPDATES
set trgDir=c:\APPFILES
for /f "delims=" %%F in ('dir %srcDir% /A-D/B/S') do call :sub "%%F"
goto :eof
:sub
set Name=%~1
set flName=!%Name:%srcDir%=%trgDir%!
if exist "%flName%" psfile "%flName%" -c
copy /Y "%Name%" "%flName%"
::::::::::::::::::::::::::::::::::::::::::::

Untested

HTH
 
To make things simple, here is an example of what I would like to achieve:

::::::::::::::::::::::::::::
set srcDir = c:\UPDATES
set trgDir = c:\APPFILES
set lenSrc = character length of srcDir (10 in this case)

for /f "delims=" %%srcFile in ('dir %src% /A-D/B/S') do (
:: next line works with the actual value of lenSrc (%flName:~10%)
set tgrFile = %trg%%flName:~%lenSrc%%
if exist "%tgrFile%" (
psfile "%tgrFile%" -c
)
)
::::::::::::::::::::::::::::

Another words, I need some sort of way to replace srcDir part of flName with
tgrDir.
 
Here is the actual script
::::::::::::::::::::::::::::::::::::::::::::
@echo off
setlocal
set srcDir=c:\UPDATES
set trgDir=c:\APPFILES
set len=10

for /f "delims=" %%F in ('dir %srcDir% /A-D/B/S') do (
call :sub "%%~F"
)

goto :eof
:sub
set Name=%~1
set flName="%trg%%Name:~10%"
set Path=%~dp1

if exist %flName% (
psfile %flName% -c
)
copy "%Name%" "%trg%%Path:~10%"
::::::::::::::::::::::::::::::::::::::::::::
 
S>B>S said:
Thanks for the response.
I did test it. Unfortunately, all flName(s) came out blank
Here is the output:

D:\>UpdateScript.cmd
copy /Y "c:\UPDATES\file1.txt" ""
copy /Y "c:\UPDATES\file2.txt" ""

Sorry a typo, one percent too much :-)

That should be:
set flName=!Name:%srcDir%=%trgDir%!
 
Thanks for the response.
I did test it. Unfortunately, all flName(s) came out blank
Here is the output:

D:\>UpdateScript.cmd
copy /Y "c:\UPDATES\file1.txt" ""
copy /Y "c:\UPDATES\file2.txt" ""
copy /Y "c:\UPDATES\file3.txt" ""
copy /Y "c:\UPDATES\abc\file4.txt" ""
copy /Y "c:\UPDATES\abc\file5.txt" ""
copy /Y "c:\UPDATES\adb\file6.txt" ""
copy /Y "c:\UPDATES\adb\file7.txt" ""
copy /Y "c:\UPDATES\adb\bcd\file5.txt" ""
 
Genius :)
Thanks so much!

Matthias Tacke said:
Sorry a typo, one percent too much :-)


That should be:
set flName=!Name:%srcDir%=%trgDir%!


--
Greetings
Matthias________________________________________
For help on nt commands enter in a cmd window:
W2K>HH windows.chm::ntcmds.htm XP>HH ntcmds.chm
 
Back
Top