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

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
 
S

S>B>S

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.
 
S

S>B>S

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%"
::::::::::::::::::::::::::::::::::::::::::::
 
M

Matthias Tacke

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%!
 
S

S>B>S

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" ""
 
S

S>B>S

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top