Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: Batch file needed to "trim" a file name  (Read 7656 times)

0 Members and 1 Guest are viewing this topic.

CindyM

    Topic Starter


    Rookie
    Batch file needed to "trim" a file name
    « on: January 16, 2008, 10:44:31 AM »
    I have a lot of files that I need to rename by trimming off the first 24 characters (letters and numbers).  This is what a typical file name looks like:

    U 0104-004 1383 1923 00 Doe, John.doc

    So basically I would like the file name to begin with the person's last name.  The numbers and letters preceding the person's last name do not stay the same, but the number of characters is constant.  I basically need to trim off the first 24 characters.  I would like to be able to do this for all files in a folder.

    Thanks!
    Cindy

    Deerpark



      Egghead
    • Thanked: 1
      Re: Batch file needed to "trim" a file name
      « Reply #1 on: January 16, 2008, 11:00:30 AM »
      Does it need to be a batch job?
      There's plenty of software that can trim characters in filenames for you. Ant Renamer for example is free.
      Any sufficiently advanced technology is indistinguishable from magic.
      Arthur C. Clarke (1917 - 2008)

      CindyM

        Topic Starter


        Rookie
        Re: Batch file needed to "trim" a file name
        « Reply #2 on: January 16, 2008, 01:39:07 PM »
        I will be doing this for loads of files, so I just don't have to have to rename them individually.  I'll check out the software you mentioned.  Thanks!

        DaveLembke



          Sage
        • Thanked: 662
        • Certifications: List
        • Computer: Specs
        • Experience: Expert
        • OS: Windows 10
        Re: Batch file needed to "trim" a file name
        « Reply #3 on: January 16, 2008, 02:19:16 PM »
        Only problem you could face if trimming common names is that the unique identifier is clipped and you then end up with two John Smith's. So if this is a very large pool of names, be sure that you dont delete people from duplicates as a result of the clipped identifiers.

        Dave

        Sidewinder



          Guru

          Thanked: 139
        • Experience: Familiar
        • OS: Windows 10
        Re: Batch file needed to "trim" a file name
        « Reply #4 on: January 16, 2008, 03:39:37 PM »
        Quote
        The numbers and letters preceding the person's last name do not stay the same, but the number of characters is constant

        This might help:

        Code: [Select]
        @echo off
        for /f "tokens=1-8 delims=. " %%a in ('dir /b *.doc') do (
        ren "%%a %%b %%c %%d %%e %%f %%g.doc" "%%f %%g.doc"
        )

        Renames that produce duplicates will fail. The original name will remain intact.

         8)

        Edit: Deleted the /s switch on the dir command. Sorry for any confusion.
        « Last Edit: January 17, 2008, 03:41:55 AM by Sidewinder »
        The true sign of intelligence is not knowledge but imagination.

        -- Albert Einstein