Hello script writers!
I have written a script with some general functions working with the full name of a file for the usage in other scripts:
GetFileExt ........... get file extension from full name of a file.
GetFileName ....... get file name without extension from full name of a file.
GetFilePath ......... get file path from full name of a file.
GetFolderName ... get name of folder a file is stored from full file name.
GetNameOfFile .... get file name with extension from full name of a file.
For all functions either the index number of an opened document or the full name of a file can be specified as an input parameter. The functions can be even used without any parameter to get the appropriate part of the full file name of the active document. The functions use only core string and UltraEdit functions. So nothing of the environment (running mode, find parameters, ...) is changed by these functions.
The script file contains also a few examples at bottom of the file. So the script file can be also simply executed to see the functions in action.
If you want to report mistakes or have suggestions for further enhancements or other useful file name functions post a message here.
The script file FileNameFunctions.js with the code can be viewed or downloaded from the Macros & Scripts page.
The line and block comments can be removed from the five functions by running a replace all (from top of file) searching with Perl regular expression for ^ *//.+[\r\n]+|^ */\*[\s\S]+?\*/[\r\n]+| +//.+$ and using an empty replace string. The first part in this OR expression with three arguments matches entire lines containing only a line comment, the second part matches block comments, and third part matches line comments right to code. Removal of the comments makes the usage of these functions in other scripts more efficient because of JavaScript interpreter has to interpret less characters and lines.
I have written a script with some general functions working with the full name of a file for the usage in other scripts:
GetFileExt ........... get file extension from full name of a file.
GetFileName ....... get file name without extension from full name of a file.
GetFilePath ......... get file path from full name of a file.
GetFolderName ... get name of folder a file is stored from full file name.
GetNameOfFile .... get file name with extension from full name of a file.
For all functions either the index number of an opened document or the full name of a file can be specified as an input parameter. The functions can be even used without any parameter to get the appropriate part of the full file name of the active document. The functions use only core string and UltraEdit functions. So nothing of the environment (running mode, find parameters, ...) is changed by these functions.
The script file contains also a few examples at bottom of the file. So the script file can be also simply executed to see the functions in action.
If you want to report mistakes or have suggestions for further enhancements or other useful file name functions post a message here.
The script file FileNameFunctions.js with the code can be viewed or downloaded from the Macros & Scripts page.
The line and block comments can be removed from the five functions by running a replace all (from top of file) searching with Perl regular expression for ^ *//.+[\r\n]+|^ */\*[\s\S]+?\*/[\r\n]+| +//.+$ and using an empty replace string. The first part in this OR expression with three arguments matches entire lines containing only a line comment, the second part matches block comments, and third part matches line comments right to code. Removal of the comments makes the usage of these functions in other scripts more efficient because of JavaScript interpreter has to interpret less characters and lines.