Add Comment
|
Related Links
|
TrackBack
GetTempPathName.bat (GPL)GetTempPathName.bat is a Windows batch file that provides your batch programs with a guaranteed unique temporary file name. Just call this script with the prefix you want for your temporary file, and this script will return an unique temporary name. Two optional parameters allows you to specify suffix for the temporary file and the directory to locate the temporary file. After calling this script, the temporary file is created to prevent another process from using the same file name. Your application should delete the temporary file after using it. GetTempPathName.bat is distributed as executable source code under the GNU General Public License. Please see the license agreement elsewhere on this site. UsageGetTempPathName.bat "prefix" ["suffix"] ["directory"] Examples> GetTempPathName.bat foo Example Batch Codecall SetVariableToOutput.bat GetTempPathName.bat %~n0 Chieh Cheng While implementing the "Random Sound Board" software, I have found a bug in this GetTempPathName.bat script. The bug is that the temporary file it creates is not empty. It contains a single line. In most cases, where you are overwriting the temporary file, it doesn't cause any problem. But if you are expecting an empty file to write to and read, then you are in for a big surprise. I've fixed the bug in the newer version of GetTempPathName.bat, which is attached below. Chieh Cheng This script outputs the temporary file path with double-quotes. If you can to get rid of the double quotes you can use the sub-string functionality of "Set". The following is an example to strip the double-quotes and assign it to a variable. call SetVariableToOutput.bat GetTempPathName.bat %~n0 Chieh Cheng I made slight changes to this "GetTempPathName.bat" script. I've fixed some of the double-quote inconsistencies. Now it outputs the temporary file names without the surround double-quote. This fix made this script more robust and easier to use in your custom scripts. Chieh Cheng It turns out, on some Windows user accounts, the temporary directory variable is not set, causing GetTempPathName.bat to fail. I have made a slight change to this version of GetTempPathName.bat to make it more robust and resolve that issue. The new version is attached below. Chieh Cheng Remember to delete the temporary file after your script is done with it. Here is an example: call SetVariableToOutput.bat GetTempPathName.bat "%~n0" Chieh Cheng Here is an example of how to use it within an if-statement with delayed expansion: SetLocal EnableDelayedExpansion 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
53 Users Online
|
Copyright © 1996 - 2024. All Rights Reserved. |