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

  • Home
  • SEARCH
  • 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 1067097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:06:35+00:00 2026-05-16T20:06:35+00:00

this may seem basic but Is there a way to create a batch to

  • 0

this may seem basic but Is there a way to create a batch to remove char from a string from a txt file. ?

If I already have this inside the .txt file

2005060.png  
2005070.png  
2005080.png  
2005090.png

so is there a way to create a batch file that will remove the .png at the end to show only this in a new .txt file

2005060  
2005070  
2005080  
2005090

Thanks for any help on this! 🙂

  • 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-16T20:06:35+00:00Added an answer on May 16, 2026 at 8:06 pm

    You can do it as per the following command script:

    @setlocal enableextensions enabledelayedexpansion
    @echo off
    set variable=2005060.png
    echo !variable!
    if "x!variable:~-4!"=="x.png" (
        set variable=!variable:~0,-4!
    )
    echo !variable!
    endlocal
    

    This outputs:

    2005060.png
    2005060
    

    The magic line, of course, is:

    set variable=!variable:~0,-4!
    

    which removes the last four characters.


    If you have a file testprog.in with lines it it, like:

    2005060.png
    1 2 3 4 5      leave this line alone.
    2005070.png
    2005080.png
    2005090.png
    

    you can use a slight modification:

    @setlocal enableextensions enabledelayedexpansion
    @echo off
    for /f "delims=" %%a in (testprog.in) do (
        set variable=%%a
        if "x!variable:~-4!"=="x.png" (
            set variable=!variable:~0,-4!
        )
        echo.!variable!
    )
    endlocal
    

    which outputs:

    2005060
    1 2 3 4 5      leave this line alone.
    2005070
    2005080
    2005090
    

    Just keep in mind that it won’t output empty lines (though it will do lines with spaces on them).

    That may not be a problem depending on what’s allowed in your input file. If it is a problem, my advice is to get your hands on either CygWin or GnuWin32 (or Powershell if you have it on your platform) and use some real scripting languages.

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

Sidebar

Related Questions

I know this may seem quite basic to geeks. But I want to make
I really have read the other articles that cover this subject. But I seem
I am developing a schema using RELAX NG. I'm pretty new to this, so
Just started reading on random way point mobility for MANET. I found a lot
Alternative wording : When will adding Double.MIN_VALUE to a double in Java not result
I have 2 linq 2 SQL statements I'd like to be in a transaction
I'm working on a web application written in Java using the Tapestry 5.1.0.5 framework.
We have an existing website which currently uses v2 of the google maps api
I want visitors to be able to click on (or copy) an email address

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.