Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8054083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T08:04:09+00:00 2026-06-05T08:04:09+00:00

How do I read and parse a file with special characters in Batch? I

  • 0

How do I read and parse a file with special characters in Batch? I have a text file named test.txt with just foo!!!bar and a batch file with this:

@echo off
setlocal enabledelayedexpansion enableextensions

FOR /F "tokens=* delims=" %%a IN (.\test.txt) DO (
    echo Unquoted is %%a
    echo Quoted is "%%a"
    set "myVar=%%a"
    echo myVar is still !myVar! or "!myVar!"
)
exit /b 0

I want and expect it to output foo!!!bar somehow, but this outputs:

Unquoted is foobar
Quoted is "foobar"
myVar is still foobar or "foobar"

Of course I can just type test.txt, but I want to process each line of the file.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T08:04:11+00:00Added an answer on June 5, 2026 at 8:04 am

    Your problem is a side effect of the batch parser and it’s phases.

    The FOR parameters are expanded just before the delayed expansion phase would be expand.
    But when %%a is foo!!bar, then the delayed expansion would remove the exclamation marks, as !! isn’t a valid variable expansion.

    You need to toggle the delayed expansion, as expanding of %%a is only safe with disabled delayed expansion.

    @echo off
    setlocal DisableDelayedExpansion enableextensions
    
    FOR /F "tokens=* delims=" %%a IN (.\test.txt) DO (
        echo Unquoted is %%a
        echo Quoted is "%%a"
        set "myVar=%%a"
    
        setlocal enabledelayedexpansion 
        echo myVar is still !myVar! or "!myVar!"
        endlocal
    )
    

    You could also look at How does the CMD.EXE parse…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to read a text file and then to parse it, in C#
Which is the best way to read and parse an Fixed Width Text File
I have to parse a file, and indeed a have to read it first,
How to parse/read a YAML file into a Python object? For example, this YAML:
I want to read and parse a text file in C++ in a generic
Is it possible to emit and read(parse) binary data(image, file etc)? Like this is
I recall I have read about a parser which you just have to feed
I have this very simple python code to read xml for the wikipedia api:
I have 75+ different text files containing some lines of dialogue spoken by characters
I am trying to read and parse a file line by line, but there

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.