views:

152

answers:

1

CMD Q: I want to remove the extension of a filename.

It is actually a complete path, like C:/Me/My/Path/filename.xxxx

i know that the extension has 4 chars, like shown in example above.

How can i get rid of the extension?

Thanks.

+2  A: 

In terminal:

set file=C:/Me/My/Path/filename.1234
for /F "tokens=*" %A IN ("%file%") DO @echo variable ^%file^%: %~dpnA

In batch file:

@echo off
set file=C:/Me/My/Path/filename.1234
echo If called with path as batch parameter: %~dpn1
for /F "tokens=*" %%A IN ("%file%") DO echo variable %%file%%: %%~dpnA
Anders
have two questions: does this also delete the dot (.)? and: how do i delete with three (123)?
YourComputerHelpZ
and: will this just change my variable, or do i have to add something to make it a variable?
YourComputerHelpZ
Do you see 4 hardcoded anywhere? it removes the last . and everything after it. It does not change the variable, to change it, replace the echo with a set
Anders
so like `set filenew=%%~dpnA`?
YourComputerHelpZ
and: is this good: `for /F "tokens=*" %%A IN ("%file%") DO set filenr=%%A.aiff`
YourComputerHelpZ
because it seems not. when i try to `echo %filenr`, it just gives `echo is off`, so it did not created the variable, or it is empty. What i did above was changing the extension in the variable to .aiff.
YourComputerHelpZ
`echo %filenr%` of course.
YourComputerHelpZ