is there a way to display the list without the quotation marks when ampersands present?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

is there a way to display the list without the quotation marks when ampersands present?

#1 Post by nnnmmm » 14 Dec 2024 21:04

C:\F9-AA1.TXT has the content below
DIR /B /O *.* &REM EEEE
DIR /B /O /A-D *.* &REM no dirs when files
DIR /B !!*.*
DIR /B *.B*
DIR /B *.EXE
DIR
------------------------------------------
@ECHO OFF
SET K1=C:\F9-AA1.TXT
FOR /F "Delims=" %%V IN ('TYPE %K1%') DO (
CALL :Z-Delayed2 "%%V"
)
GOTO :EOF
:Z-Delayed2
SET "Sname=%~1"
SET "U=%Sname%"
SET H="%U%"
ECHO %H:~1,-1%
@EXIT /B

how can i display the list content without the quotation marks when there might be ampersands present? &REM remarks must be shown since they can explain the options to me.
*restrictions
1. hope to use CALL, because the strings from %%V will be heavily edited later (with FOR, IF, SET), this call structure is one i am going for at the moment
2. must NOT use SetLocal EnableExtensions EnableDelayedExpansion - i am done +20 years over flondering with EnableDelayed and "!" conflicts, i am removing all essential EnableDelayedExpansion from my batches but then i start to have a new problem with &. but i'd figure if & were not a real part of the batch operators for my use, then i might have a chance.

Sponge Belly
Posts: 233
Joined: 01 Oct 2012 13:32
Location: Ireland
Contact:

Re: is there a way to display the list without the quotation marks when ampersands present?

#2 Post by Sponge Belly » 18 Dec 2024 10:47

Hi nnnmmm,

Here’s an old trick I learnt from Jeb:

Code: Select all

for %%^" in ("") do echo(%%~"poison characters ! ^ & < | > without quotes%%~"
Read this SO Q&A for the full story.

Ho ho ho! :)

- SB

jeb
Expert
Posts: 1058
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: is there a way to display the list without the quotation marks when ampersands present?

#3 Post by jeb » 26 Dec 2024 04:57

And I learned a new variant for the trick last month, now it's enough to use %%" instead of %%~".

Code: Select all

FOR /F "tokens=* delims=X" %%^" in ("X") do (
  echo %%" Special characters &..|..^..<..>
  echo %%" Event a closing bracket ) doesn't harm
)
It's possible to create a single FOR meta-variable that's empty.
Previously it was only possible to create empty meta variables after a leading meta variable with content.

nnnmmm
Posts: 181
Joined: 26 Aug 2017 06:11

Re: is there a way to display the list without the quotation marks when ampersands present?

#4 Post by nnnmmm » 27 Jan 2025 22:03

sorry about late response, i didnt think i would get an answer, i kind of gave up.
at the moment, i kind of read some of other posts, it might take a while for me to grab them to make a proper response as to if i can incorporate them into my batch or not.
i tried a few ways... didnt work

@ECHO OFF
SET K1=C:\F9-AA1.TXT
FOR /F "tokens=* Delims=&" %%^" IN ('TYPE %K1%') DO (
CALL :Z-Delayed2 "%%^"
)
GOTO :EOF

:Z-Delayed2
SET "Sname=%~1"
SET "U=%Sname%"
SET H="%U%"
ECHO %%" %H:~1,-1%
@EXIT /B

Post Reply