Add default extension

[Autolink] Menu

 
/* ------------------------------------------------------------------ */
/* function: Add a default extension to a filename if necessary       */
/*                                                                    */
/* usage:    newFileName = CheckExtension( fileName, extension )      */
/*                                                                    */
/* where:    fileName = the filename to check                         */
/*           extension = default extension                            */
/*                                                                    */
/* returns:  the filename with extension                              */
/*                                                                    */
CheckExtension: PROCEDURE expose (exposeList)
  parse arg fileName, extension

                        /* init the return code                       */
  thisRC = fileName

  if fileName <> '' & extension <> '' then
  do
    dotPos = lastpos( '.', fileName )
    backslashPos = lastpos( '\', fileName )

    if ( dotPos <= backslashPos ) then
      thisRC  = fileName || extension
  end /* if fileName <> '' & extension <> '' then */

return thisRC


[Back: Copy a file with a progress indicator]
[Next: Runtime tests & methods]