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

Author Topic: REMOVING n' CHARACTERS FROM THE END OF A DOS FILE  (Read 6807 times)

0 Members and 1 Guest are viewing this topic.

BRIANH

    Topic Starter


    Rookie

    • Experience: Familiar
    • OS: Windows XP
    REMOVING n' CHARACTERS FROM THE END OF A DOS FILE
    « on: January 17, 2021, 01:39:48 PM »
    Hi... I am trying to find a way to remove 'n' characters fro ALL files in a DOS directory. I found this on the web but it doesn't work.
    I am not overly familiar with DOS and cmds so any help will be greatly appreciated..  many thanks

    tried:@echo off
            setlocal enabledelayedexpansion
            set FOLDER_PATH="D:\Some DOS CMDS\NEW FOLDER"
            for %%f in (%FOLDER_PATH%*) do if %%f neq %~nx0 (
                set "filename=%%~nf"
                ren "%%f" "!filename:~0,-26!%%~xf"
    )
    PAUSE

    Sidewinder



      Guru

      Thanked: 139
    • Experience: Familiar
    • OS: Windows 10
    Re: REMOVING n' CHARACTERS FROM THE END OF A DOS FILE
    « Reply #1 on: January 20, 2021, 12:07:41 PM »
    Sometimes I can be a bit slow on the uptake, but why eliminate characters from file names on a mass scale? While you ponder that, this little piece of doggerel may just help.

    Code: [Select]
    @echo off
    setlocal enabledelayedexpansion
    set folder=c:\temp

    for /f %%f in ('dir /b /a-d %folder%') do (
      set input=%%f
      set output=!input:n=!
      ren %folder%\!input! !output!
    )

    pause

    Be sure to change the folder name in the third line.

    Happy Coding  8)
    The true sign of intelligence is not knowledge but imagination.

    -- Albert Einstein