Scripts

Determine whether a given file exists

The script determines whether a given file exists in the Uscripts folder. If a file already exists, the script adds a sequential number to the file name. The script thus prevents from accidentally deleting existing output or transcript files.
Download: script40.sc [1.6kb]

\* --------------------------------------------------------------------
\* STN Express Script
\* Name:  filenaming.sc
\* Description: The script determines whether a given file exists in
\* the Uscripts folder. If a file already exists, the
\* script adds a sequential number to the file name. The
\* script thus prevents from accidentally deleting
\* existing output or transcript files.
\* Authors:  Christoph Neuhaus, ETH Zurich
\* Andreas Litscher, InfoLit Infobroker GmbH, Bern
\* Date:  02.01.2008
\* Version:  1.0
\* --------------------------------------------------------------------



\* Path of your STN Express installation
\* (e.g. "c:\\STNEXP" or "c:\\Program Files\\STNEXP")
_stnepath = "c:\\STNEXP"

\* Path of your output file
_outputfile = "_stnepath"+"\\Uscripts\\output.txt"
\* Initialize sequential number
_i = 1
@rename
\* Check whether a file exists
exists <_outputfile>
\* If a file already exists, add a sequential number to the file name
if (_$filerror = 0)
begin
_i = _i + 1
_outputfile = "_stnepath"+"\\Uscripts\\output"+"_i"+".txt"
goto @rename
end

\* Open file for testing
capture on <_outputfile>
capture off <>
if (_$filerror = 1)
begin
goto @outerror
end

\* Write output to file
echo "hello world"
goto @end

\* Error message
@outerror
echo ""
echo "Error: output file not found"
echo ""
goto @end

@end
\* Exit
echo ""
echo "****** END OF SCRIPT ******"
echo ""
exit
\* --------------------------------------------------------------------

Comments

I suggest adding a “google+” button for the blog!
Hellen
Comment by Buy Ellipticals posted on 12/11/2011

Post a comment

Enter your comments to the field below.



Name (required):  
Email (required):  
Type the code:

  Save personal information
  Receive notifications for this comment