Add Comment
|
Related Links
|
TrackBack
basename.bat (GPL)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. Usagebasename.bat "path" Example> basename "\Users\Medusa\Documents\My Games\Dawn of War 2" Chieh Cheng 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. SetNumberOfArguments.bat Usagebasename.bat "path" [ "suffix" ] Print NAME with any leading directory components removed. If specified, also remove a trailing SUFFIX. ExamplesC:\>basename "Puppet\mainwindow.statenull" Chieh Cheng You're basename.bat seems to be having problems if a file has a ) inside its name, for folders it works ok. C:\>basename "C:\ABC(CBA)\xyz.ext" C:\>basename "C:\ABC\xyz(zyx).ext" C:\>basename "C:\ABC\xyz(zyx).ext" Paul 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: with extention: without extention: extention only: drive letter & dirname Paul Thanks Paul, I'll take a look at your examples and the bug when I have a chance. Chieh Cheng 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. Chieh Cheng I discovered that "basename.bat" cannot handle file names with '!' in them. So I have fixed that problem in this latest version (see attached). Chieh Cheng
Add Comment
|
Related Links
|
TrackBack
Did your message disappear? Read the Forums FAQ. Add CommentSpam Control | * indicates required field TrackBackTrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites. Send Ping | TrackBack URL | Spam Control 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. |
Products
|
Services
44 Users Online
|
Copyright © 1996 - 2024. All Rights Reserved. |