delete the leading characters of a file

Posted on 2007-07-24
Last Modified: 2010-04-16
I have a lot of files that start with XXXXX-123456

I would like to run a .bat that will delete the leading XXXXX- to these files. I have other files in this folder so I would like only the XXXXX- files to be effected ??????????
Question by:zyanj
    LVL 30

    Expert Comment

    Try this. I've disabled the ren command by placing an echo statement prior to it. To enable it remove the echo command:

    @echo off

    setlocal enabledelayedexpansion

    set filePrefix=XXXXX-

    for /f "tokens=*" %%a in ('dir /b /a-d "%filePrefix%*.*" 2^>NUL') do call :PROCESS "%%a"

    goto :EOF


    set newFileName=%~1
    set newFileName=!newFileName:%filePrefix%=!

    REM ** Remove echo to enable the ren command
    echo ren "%~1" "%newFileName%"

    goto :EOF
    LVL 66

    Accepted Solution


    If you would prefer a GUI version...


    Author Comment

    Wow Rename4U is great Thanks!!!!!!!!
    LVL 66

    Expert Comment

    Your welcome!!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    This article was inspired by a question here at Experts Exchange ( The requirements stated in that question are (1) reduce the file size of a large number of…
    This is about my first experience with programming Arduino.
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now