fileNameFormat ( )

Function stats

Average user rating
166
420
9999
Support
FileMaker 7.0 +
Date posted
13 March 2019
Last updated
07 May 2019
Version
Recursive function
No

Author Info
 Josh Ormond

5 functions

Average Rating None

author_avatar



 

Function overview

Prototype

fileNameFormat  ( _path;   _fileName;   _date;   _fileExt;   _theDatePosition )


Parameters

_path  Path to the file, excluding the file name. Default is Get ( DocumentsPath )


_fileName  the desired name of the file being created.


_date  the date to append to the file name. Default is Get ( CurrentDate ).


_fileExt  the extension for the file being created.


_theDatePosition  position the date before or after the fileName. Default is before. 0 =


Description

Tags:  filename   file  

Return the full path, including file name with a formatted date. The _path, _date, and _datePosition all have built in defaults.

There is also a helper function that only requires the _fileName and _fileExt parameters, and sets the defaults for you. Function name is fileFormatDefault.

Examples

Sample input

fileNameFormat ( Get ( DesktopPath ) ; "SalesReport" ; Get ( CurrentDate ) ; "pdf" ; "after" )
fileNameFormat ( "" ; "SalesReport" ; "" ; "pdf" ; "" )


Sample output

/Macintosh HD/Users/johndoe/Desktop/SalesReport_2019-03-13.pdf
/Macintosh HD/Users/johndoe/Documents/2019-03-13_SalesReport.pdf

 

Function code

/***************************************
*
*    Function Name:        fileNameFormat ( _path ; _fileName ; _date ; _fileExt ; _datePosition )
*
*    Parameters:        _path = path to the file, excluding the file name. Default is Get ( DocumentsPath ).
*                    _fileName = the desired name of the file being created.
*                    _date = the date to append to the file name. Default is Get ( CurrentDate ).
*                    _fileExt = the extension for the file being created.
*                    _datePosition = position the date before or after the fileName. Default is before. 0 = "before", 1 = "after".
*
*    Purpose:            Easy formating of the string used for various paths and file creation. For example, exporting records.
*
*    Notes:            - Using "" will use the defaults for path, theDate, and datePostion parameters.
                    - For datePosition, "before" is converted to 0, and "after" is converted to 1.
                    - there is a wrapper function called fileNameDefault, that inserts the defaults for you.
*
*    Change log:        2019-02-28 JO - Initial build.
*                    2019-03-04 JO - added missing letters for theFileExt filter, and converted to all lowercase.
*
*****************************************/

Let (

[

thePath = Case ( IsEmpty ( _path ) ; Get ( DocumentsPath ) ; _path ) ;
theFileName = _fileName ;
theFileExt = "." & Filter ( Lower ( _fileExt ) ; "abcdefghijklmnopqrstuvwxyz1234567890" ) ;
theDate = Case ( IsEmpty ( _date ) ; Get ( CurrentDate ) ; GetAsDate ( _date ) ) ;
theDatePos = Substitute ( _datePosition ; [ "before" ; 0 ] ; [ "after" ; 1 ] ) ; // 0 = before, 1 = after

y = Year ( theDate ) ;
m = Right ( "00" & Month ( theDate ) ; 2 ) ;
d = Right ( "00" & Day ( theDate ) ; 2 ) ;
formattedDate = y & "-" & m & "-" & d ;


result =
Case (

    theDatePos = 0 ;
        thePath & formattedDate & "_" & theFileName & theFileExt ;

    theDatePos = 1 ;
        thePath & theFileName & "_" & formattedDate & theFileExt ;

        thePath & formattedDate & "_" & theFileName & theFileExt

)

] ;

result

)

// ===================================
/*

    This function is published on FileMaker Custom Functions
    to check for updates and provide feedback and bug reports
    please visit http://www.fmfunctions.com/fid/420

    Prototype: fileNameFormat( _path; _fileName; _date; _fileExt; _theDatePosition )
    Function Author: Josh Ormond (http://www.fmfunctions.com/mid/166)
    Last updated: 07 May 2019
    Version: 1.3

*/
// ===================================