You are not logged in.
Pages: 1
I have a problem with using the "Replace" within a For-loop.
How can I achive that OriginalPathFileName=PathFileName with abc%~1 (ex abc4,abc15,...) removed from it
@echo off
setlocal enableDelayedExpansion
FOR /L %%I IN (1,1,99) DO call :Process-Number %%I
:Process-Number
for /R "E:\Files" %%A in ("*abc%~1.doc") do (
set PathFileName=%%A
set PathFileNameNumber=abc%~1
set OriginalPathFileName=!!PathFileName:%PathFileNameNumber%=!!
)
Last edited by wquatan (08 Jul 2016 09:53)
Offline
Look through this thread for some ideas and post your working code here.
Last edited by sambul35 (07 Jul 2016 18:23)
Offline
You have double "!!" -- they don't make sense syntactically.
You're setting PathFileNameNumber inside the "for /R" loop and then trying to use it within the same loop using "%" notation (and you can't nest ! notation) -- this won't work.
Try this:
:Process-Number
set "PathFileNameNumber=abc%~1"
for /R "E:\Files" %%A in ("*%PathFileNameNumber%.doc") do (
set "PathFileName=%%A"
set "OriginalPathFileName=!PathFileName:%PathFileNameNumber%=!"
)
Last edited by bluesxman (08 Jul 2016 14:06)
cmd | *sh | ruby | chef
Offline
How can I achive that OriginalPathFileName=PathFileName with abc%~1 (ex abc4,abc15,...) removed from it
Something seems wrong in your problem newly edited definition or code. Did you mean that %~1 is the 1st and only argument of your batch? Why then it has a series of values like abc4,abc15,...? Can you post that code printout, when the batch is called with all arguments and executed?
Last edited by sambul35 (08 Jul 2016 14:26)
Offline
@bluesxman
Yeah, the !! was the last thing I tried.
It's solved know, and as you suggested, it was the [set PathFileNameNumber=abc%~1] which needed to be before the FOR.
The [set OriginalPathFileName=!PathFileName:%PathFileNameNumber%=!], one of those I tried, works now.
Thanks !!!
@sambul35
The (ex abc4,abc15,...) was from the beginning in my post and was intented as a list of examples for the %1 parameter
The call is also in the code I posted
Thanks
The working code :
@echo off
setlocal enableDelayedExpansion
FOR /L %%I IN (1,1,99) DO call :Process-Number %%I
:Process-Number
set PathFileNameNumber=abc%~1
for /R "E:\Files" %%A in ("*%PathFileNameNumber%.doc") do (
set PathFileName=%%A
set OriginalPathFileName=!PathFileName:%PathFileNameNumber%=!
)
Last edited by wquatan (08 Jul 2016 23:35)
Offline
Pages: 1