How to change a bunch of filenames to remove some characters

Posted on 2009-12-28
Last Modified: 2012-05-08
Folder containing hundreds of mp3 files. Each file has a spurious bumber and space at the front of the filename which I need to remove.

Example 1: 07 some song or other.mp3
Example 2: 1-14 some other song.mp3

I thought I'd be able to do it at the command line using REN "07 *.mp3" *.mp3, but no dice

Any suggestions for how to do this from the command line?

Just to emphasise, I need to lose the space as well as the numbers at the front of the filename.

OS = Win7
Question by:richardbarlow

    Expert Comment

    Select all
    Right click
    click on rename
    and enter name for example - mymusic

    It will rename all to mymusic01, mymusic02.....

    Expert Comment

    I am using "Better File Rename" software like your operation. it is so useful.
    LVL 43

    Accepted Solution

    From a command prompt you could construct a batch file as follows using notepad and save in the dir with the filenames:
    @echo off
    for /f "tokens=1* delims= " %%a in ('dir /a-d /b *.mp3') do echo rename "%%a %%b" "%%b"

    This takes a dir listing in bare format (/b) of files only (/a-d) and then for each line in the file splits the line at the first space.  The bit before the space goes to %%a and the rest of the name and extension to %%b .

    If the rename comands look right on the screen then remove the word echo to make it actually do the renames...

    You can also do 'search and replace' using same technique to remove other parts of the filename such as 'DVDRip' or a tag name etc. if needed.  The batch gets a bit more complicated then having to use delayed expansion but can show if needed.

    LVL 43

    Expert Comment

    by:Steve Knight
    I should have said, if you want to run from a command prompt directly, rather than from a batch file just replace the %% with %, i.e.

    for /f "tokens=1* delims= " %a in ('dir /a-d /b *.mp3') do rename "%a %b" "%b"

    Of course if there are multiple files with the same name after first space then a rename will fail on those.  If that is possible we could carry out a check too..


    Author Closing Comment

    Excellent answer. Thank you
    LVL 43

    Expert Comment

    by:Steve Knight
    No pblem, glad it helped.


    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
    Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

    746 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

    15 Experts available now in Live!

    Get 1:1 Help Now