Solved remove last blank space befor extension (in file names)

March 31, 2014 at 03:00:26
Specs: Windows XP
hi there
i need a batch script
i have lots of files i want to remove blank spaces before extension (just those blank spaces that located before extension and not other ones)
look at example below
sads gd .txt
should rename to
sads gd.txt

i have fond script below but it remove any characters from end of file's name before extension
but i want just blank and empty spaces be removed and not any other characters
here is the batch script

SETLOCAL enabledelayedexpansion
FOR %%t IN (*.txt) DO (
CALL :process "%%~nt"
IF DEFINED success REN "%%t" "!success!%%~xt"
GOTO :eof

SET "success=%~1"
SET "lastchar=%success:~-1%"
SET "success=%success:~0,-1%"

message edited by mioo_sara

See More: remove last blank space befor extension (in file names)

Report •

March 31, 2014 at 05:33:40
✔ Best Answer

@echo off & setlocal EnableDelayedExpansion
for /F "delims=" %%i in ('dir /B *.txt') do (
  set name=%%~ni
  set ext=%%~xi 
  if "!name:~-1,1!"==" " (set name=!name:~0,-1!& ren "%%i" "!name!!ext!")

Report •

March 31, 2014 at 05:45:49
thanks dear IVO
you solved my problem it works like a charm
thanks again

message edited by mioo_sara

Report •
Related Solutions

Ask Question