This "basename.bat" is a Windows batch program that performs the same function as as the UNIX "basename" command. And that function is to strip the parent directory prefix from specified path. You can call this script from your own custom batch script to extract the file name.
"basename.bat" takes advantage of the SetNumberOfArguments.bat (GPL) script that is available on this web site. So to use "basename.bat", you'll have to download SetNumberOfArguments.bat, if you don't already have it.
"basename.bat" is distributed as executable source code under the GNU General Public License. Please see the license agreement elsewhere on this site.
> basename "\Users\Medusa\Documents\My Games\Dawn of War 2"
I have improved "basename.bat" to support the ability to strip a suffix from the name. This improvement brings "basename.bat" more inline with what the UNIX version does.
This version of "basename.bat" takes advantage of the following batch files that are available on this site. You must download these batch files as well, if you don't already have them.
basename.bat "path" [ "suffix" ]
Print NAME with any leading directory components removed. If specified, also remove a trailing SUFFIX.
You're basename.bat seems to be having problems if a file has a ) inside its name, for folders it works ok.
Thanks for the scripts, been using them for quite a while :P
But there seems to be a simpler solution to some of your scripts:
drive letter & dirname
Thanks Paul, I'll take a look at your examples and the bug when I have a chance.
Paul, I looked at the problem and at your potential solutions. I was tempted to replace the entire content of basename.bat with your examples using "for" statements. However, I decided not to, because the "without extension" example will not match the UNIX implementation of "basename". I wanted to keep the Windows version of "basename.bat" as close to the UNIX version as possible.
Therefore, I fixed the problematic areas in the code. It turns out that Windows is interpreting the parentheses as part of its language syntax. So, sadly, I fixed it by reverting back to the ancient school of unstructured batch programming. The fixed version is attached below.
This problem also affected "StrLen.cmd", which "basename.bat" uses. I fixed that script as well. You'll have to download both scripts to eliminate the problem completely.
I discovered that "basename.bat" cannot handle file names with '!' in them. So I have fixed that problem in this latest version (see attached).
Did your message disappear? Read the Forums FAQ.
Spam Control | * indicates required field
TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.
No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here.
Messages, files, and images copyright by respective owners.
24 Users Online
Copyright © 1996 - 2021. All Rights Reserved.