Where are my percenties? %% and call

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Where are my percenties? %% and call

#1 Post by Endoro » 15 Apr 2013 05:29

The "call" command removes percent signs.

I have two subdirs in my test folder, the second from real life:

Code: Select all

C:\TEST>dir /ad /b
%no%more%alcohol%
Alcohol 120%


And use this test code:

Code: Select all

@echo off &setlocal
for /d %%i in (*) do (
   echo before call: "%%~i"
   call:process "%%~i"
   echo(
)
goto:eof

:process
echo after  call: "%~1"
exit /b


And this is the output from the code:

Code: Select all

before call: "%no%more%alcohol%"
after  call: "more"

before call: "Alcohol 120%"
after  call: "Alcohol 120"


I need the call in a recursive function here.
What can I do to avoid this?

Endoro
Posts: 244
Joined: 27 Mar 2013 01:29
Location: Bozen

Re: Where are my percenties? %% and call

#2 Post by Endoro » 15 Apr 2013 05:55

Sorry, I was a bit confused ... :oops:

Code: Select all

@echo off &setlocal
set "line="

for /d %%i in (*) do (
   echo before call: "%%~i"
   set "line=%%~i"
   call:process "%%~i"
   echo(
)
goto:eof

:process
echo after  call: "%~1"
echo the    line: "%line%"
exit /b


Output:

Code: Select all

before call: "%no%more%alcohol%"
after  call: "more"
the    line: "%no%more%alcohol%"

before call: "Alcohol 120%"
after  call: "Alcohol 120"
the    line: "Alcohol 120%"


Thank you, and please ignore this.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Where are my percenties? %% and call

#3 Post by foxidrive » 15 Apr 2013 06:20

Using % in a filename or foldername is a problem. You have to use workarounds and give them special treatment, like processing them manually if you can't rename them at all.

Post Reply