remove file extension from name batch script

July 23, 2011 at 10:08:24
Specs: Windows 7
Hey! Could someone please tell me how to write a batch script to take a file name as an argument, and return only the NAME, without the EXTENSION.

eg:
input=> batFile C:\hello.txt
output=> hello


See More: remove file extension from name batch script

Report •


#1
July 23, 2011 at 13:00:05
Hi

@echo off
call :Name "c:\Harry Trevor.txt"
exit /b

:Name %1
for /f "tokens=* delims=" %%a in ("%~1") do (
set Name=%%~na
)
echo Name=%Name%
exit /b


Report •

#2
July 24, 2011 at 22:50:40
thanks for the response!
i found a simpler solution, though:

if the file name is stored in %1, then the name WITHOUT the extension can be got by using %~n1.

-divs1210


Report •
Related Solutions


Ask Question