delete text in filename after character

Microsoft Windows 7 professional 64-bit
August 8, 2010 at 13:19:26
Specs: Windows 7, C2D E6700
I need a batch file that will rename all files after a particular character


renamed to:

Basically, as soon as the filename contains an Underscore, all text in the filename from that point on should be removed. I messed with the rename command but it does not do what I want, it leaves the files the same.

See More: delete text in filename after character

Report •

August 8, 2010 at 15:57:00

 @echo off & setLocal EnableDELAYedeXpansion

for /f "tokens=* delims= " %%a in ('dir/b ^| find "_"') do (
  set N=%%~Na
  call :sub1
  echo ren %%a !N!%%~Xa

goto :eof


for /L %%i in (1 1 22) do (
  set S=!N:~%%i^,1!
    if !S! equ _ (
      set N=!N:~0,%%i!
      goto :done

goto :eof

Helping others achieve escape felicity


Report •

August 9, 2010 at 10:10:07
That worked perfectly, thanks a million!

Report •

August 10, 2010 at 01:30:56
edit: nevermind, found it! just had to experiment with the file

Report •

Related Solutions

Ask Question