FileMapName

Transforms a filename with a file wildcard mask and returns a new filename.

Syntax:

FileMapName(filename, mapping-data).

Parameters:

(s) filename full or partial file name.

(s) mapping data mapping and wildcard definition string (see below).

Returns:

(s) transformed file name.

 

Use this function to generate a new filename based on an old filename. It can be used to generate *.bak filenames easily, or to perform assorted wildcard transformations on a filename. The mapping-data consists of the normal (optional) drive, path, legal filename characters, the period, and two special wildcard characters, the asterisk (*) and the question mark (?). The following algorithm is used to transform the file name:

 

1) If drive is specified in the mapping-data use specified drive, else use current drive.

 

2) If path is specified in the mapping-data use specified path, else use current path on the drive selected above.

 

3) Examine root of the filename and root position of mapping-data, sequencing through the root characters together, one character at a time.

 

map-char root transformation rule

. If the mapping position character is a period, stop processing the root filename, add a period to the end of the new filename string and proceed to process the extension as outlined below.

* If mapping data position is a asterisk, copy remainder of root file name to new filename string and proceed to process the extension as outlined below.

? If mapping data position is a question mark, copy the current character from the root filename to the new filename string.

other If the mapping data character is not one of the above, copy the map character to the new filename string and ignore the corresponding character in the root filename.

<none> If there are no more characters in the mapping-data string, filename generation is complete. Return with the new string.

 

4) Examine extension of the filename and extension position of mapping-data, sequencing through the extension characters together, one character at a time.

 

map-char extension transformation rule

* If mapping data position is a asterisk, copy remainder of extension file name to new filename string and return.

? If mapping data position is a question mark, copy the current character from the extension filename to the new filename string.

other If the mapping data character is not one of the above, copy the map character to the new filename string and ignore the corresponding character in the extension filename.

<none> If there are no more characters in the mapping-data string, filename generation is complete. Return with the new string.

 

This function supports extended-length path names.

Example:


DirChange("C:\TEMP")
a=FileMapName("d:\sample\xxx.txt", "*.bak")
Message("New filename", a)
; This will return C:\TEMP\XXX.BAK
;
a=FileMapName("d:\sample\xxx.txt", "c:\demo\??Q.bak")
Message("New filename", a)
; This will return C:\DEMO\XXQ.BAK
See Also:

AskFileName, FileFullName, FileCopy, FileMove, IntControl 91