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 7218561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T21:29:56+00:00 2026-05-28T21:29:56+00:00

I have bat-script with following code: FOR /F tokens=1,2 delims== %%g in (%CFGFILE%) do

  • 0

I have bat-script with following code:

FOR /F "tokens=1,2 delims==" %%g in ("%CFGFILE%") do (
  SET firstChar=%%g
  SET firstChar=!firstChar:~1,1!
  if /I "!firstChar!"=="#" (
    echo %%g>>"%INSTALL_PATH%\tmp.cfg"
  )else (
    if /I "%%g"=="document.folder" (
      SET path_written=TRUE
      echo %%g=%DOC_FOLDER%>>"%INSTALL_PATH%\tmp.cfg"
    )else (
      rem next line is buggy
      echo %%g=%%h>>"%INSTALL_PATH%\tmp.cfg"
    )
  )
)

The point is parsing cfg-file %CFGFILE% contents and copying every string without changes to new config-file, except only one string starting with “document.folder”. This line must be changed. Problem is that the line after “next line is buggy” comment gives “c:\program files\myApp\original.cfg=” which is content of %CFGFILE% variable plus equals sign. Is this a bug or i’ve done something wrong? Is this connected with %%x variables visibility?

  • 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-05-28T21:29:57+00:00Added an answer on May 28, 2026 at 9:29 pm

    You have mis-identified the source of the problem! 🙂

    Your problem is in the very first line – your FOR statement is processing a string, not a file, because the IN() clause is enclosed by double quotes. If you want the IN() clause to be treated as a quoted file name, then you need to add USEBACKQ to your FOR options.

    FOR /F "usebackq tokens=1,2 delims==" %%g in ("%CFGFILE%") do (
    

    Just a heads up – even after the fix above, your code will not give the correct results if any of the following conditions appear

    • If any line contains ! then expansion of %%g or %%h will be corrupted because delayed expansion is enabled

    • Commented # line will be incomplete if the original contained =

    • Your normal lines will not be complete if there is a 2nd = in the original

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

Sidebar

Related Questions

I have the following bat script: @echo off set JAVA_HOME=C:\Program Files\Java\jdk1.6.0_32 set JRE_HOME=C:\Program Files\Java\jdk1.6.0_32\jre
I'm trying to write a BAT script and I have the following: @echo off
I have the following in a BAT file: @echo off Set /P _environment =
I have a batch script that looks like this: Test.bat @echo off :: Starts
I have scrip contain command line: set dir=%1 cd %dir% test.bat echo successful When
I have bat file like below with name myBat.bat 1) @echo off set CLASSPATH=%CLASSPATH%;C:\Documents
I have created below bat file to run my RMI server @echo Off set
I have a file invisible.vbs having following script Set WshShell = WScript.CreateObject(WScript.Shell) obj =
I have a Windows batch script (my.bat) which has the following line: DTBookMonitor.exe 2>&1
I'm writing a bat script and I have to save the date from a

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.