Bite my bytes

What I learn by day I blog at night - A blog from Microsoft Consultant working from Ljubljana, Slovenia

  Home :: Contact :: Syndication  
  999 Posts :: 7691 Comments :: 235 Trackbacks

Search

Most popular posts
in last 30 days

Categories

My Projects

Archives

Stuff


Copyright © by David Vidmar
 
Contact me!
 
LinkedIn Profile
 
 
 

There is a hard way of getting filename only from a path. Or extension from a path. And there is a sweet n’ simple way to do it.

The trick is to separate your code in another batch file and call it with parameters. In that batch file you can use for example %~n1 to get filename only of passed path.

Why I needed that? Well, that’s a very good question indeed….

Posted on Sunday, November 12, 2006 10:37 PM | Filed under: System |

Feedback

# re: File name or extension only in batch files 4/23/2010 2:21 AM Jesse Chisholm
Another short cut is to doo it all in one file:

[code]
call :separate filename.ext
echo NAME=%NAME%
echo EXT=%EXT%
goto EOF
:separate
set FILE=%~n1
set EXT=%~x1
exit /b 0
:EOF
[/code]

# re: File name or extension only in batch files 5/13/2010 6:44 AM ray
Jesse, had a great example, but it had a typeo:
[code]
@echo off
call :separate "dude.txt"
echo FILE=%FILE%
echo EXT=%EXT%
goto EOF
:separate
set FILE=%~n1
set EXT=%~x1
exit /b 0
:EOF
[/code]

# re: File name or extension only in batch files 6/24/2011 12:27 PM Swetal Gajjar
Thanks a lot.

This worked for me :)

Comments have been closed on this topic.