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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T19:30:59+00:00 2026-05-25T19:30:59+00:00

I would like to be able to edit a txt file with a batch

  • 0

I would like to be able to edit a txt file with a batch file. This is a bit complicated by a number of things.

First, the file name is frog.properties and opens just fine in notepad but on the computers this will be run on; the file type of .properties is not associated with Notepad. If the file needs to it can make the association but I’d like to avoid that.

Second, the text that needs edited is a single line in the file. The first 9 characters on the line we want to edit are unique to that line and will remain the same after the edit. However, where that line is located in the file and what comes after it on that line will vary from machine to machine. The line can be moved in the file no problem if it needs to be removed and added into the end.

So far I found the code listed below found here and edited it slightly. Right now when I run the batch file (named replace.cmd or replace.bat) it just echoes “this file does not exist” and exits the prompt. I have verified that the file is in the location.

In the future I would like to be able to recycle this code to easily use it to edit any .ini or txt file by just changing file location and text to find and edit. The type of file that this can be run from needs to be .bat or .cmd because of the environment I will be using this in.

Thank you.

@echo off
setlocal enabledelayedexpansion

if not exist "%1" (echo this file does not exist...)&goto :Failed


for /f "tokens=* delims=" %%a in (%1) do (

   set write=%%a
   if "%%a"=="%2" set write=%3

   echo !write! 
   (echo !write!)>>%~n1.replaced%~x1
)

replace "C:\Users\ME\Desktop\test.txt" "withquot=*" "withquot=it worked"

pause
:Failed
pause

UPDATE 09/20/2011

Right now the file will echo “this file does not exist” and pause. So I removed the line if not exist "%1" (echo this file does not exist...)&goto :Failed

and I get

invalid Switch - "withquot=it worked"
I have tried removing the “=” from the invalid switch and I get the same invalid switch I have tried using set to set the individual variables and changed the references in the file. I have tried moving the test file to the root of C and changing the reference.

The test file currently looks like this

test file
withquot=didntwork
USING_LOCAL_SHARED_MEM=1

Nothing I seem to do will get this file to work, I must be missing something small or am going in the complete wrong direction with this file. I have tested the file on Vista and Windows 7. Is something wrong with the file that you can see?

Bottom line, I don’t care how but I want to be able to edit a .txt file with a batch file, and be able to do a line replace.

  • 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-25T19:30:59+00:00Added an answer on May 25, 2026 at 7:30 pm

    I still really want to know how to do this in a batch file but I found a way using a vbs script from here. using a .cmd file or a .bat file I kept running into the issue of having a = in the find or replace messing everything up.

    I changed the file from that location to Loop on Arguments 2 to X so that the format for the file is Find (0) Replace with (1) in location (2) and (3) and (4)…

    Option Explicit
    
    Const ForReading = 1
    Const ForWriting = 2
    Dim Puppet, strOld, strNew, i
    Puppet = 0
    strOld = WScript.Arguments.item(0)
    strNew = WScript.Arguments.item(1)
    i = 1
    
    On Error Resume Next
    Do While i <= WScript.Arguments.count
        i = i + 1
        Call update(WScript.Arguments.item(i), strOld, strNew)
        Puppet = Puppet Or (Err.Number = 0): Err.Clear
    Loop
    On Error GoTo 0
    
    Sub update(strFile, strOld, strNew)
    Dim objFSO, objFile, strText, strNewText
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFile = objFSO.OpenTextFile(strFile, ForReading)
    strText = objFile.ReadAll
    objFile.Close
    strNewText = Replace(strText, strOld, strNew)
    Set objFile = objFSO.OpenTextFile(strFile, ForWriting)
    objFile.WriteLine strNewText
    objFile.Close
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to be able to edit text in a UITextField like this:
I would like the user to be able to edit the title of the
I would like to be able to bulk edit all the rows for one
I would like to be able to edit conflicts using DiffMerge but when I
Our client would like to be able to edit a few pages on their
I've been thinking, I would like to able to assign different messages different priorities
Would like to be able to set colors of headings and such, different font
I would like to be able to detect a square edges on variable zoom
I would like to be able to pass some context info between NLog loggers
I would like to be able to add the difference and percent change to

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.