infinity.fileName¶
Provides helper functions for extraction of file paths, names and extensions.
Module: infinity.fileSystem
correct()¶
Returns a valid filename from the given string.
Signature:
correct( fileName: string ): string
Parameters:
- fileName:
string
The filename to be corrected.
Return type: string
Example:
infinity.loadModule('infinity.fileSystem');
let validFileName = infinity.fileName.correct(fileName);
extension()¶
Returns the extension out of the given filename
Signature:
extension( fileName: string ): string
Parameters:
- fileName:
string
The filename to examine.
Return type: string
Example:
infinity.loadModule('infinity.fileSystem');
let s = infinity.fileName.extension('test.txt');
console.debug(s);
//.txt
expand()¶
Returns the given relative file path converted to an absolute one.
Signature:
expand( fileName: string ): string
Parameters:
- fileName:
string
A relative file path.
Return type: string
Example:
infinity.loadModule('infinity.fileSystem');
let s = infinity.fileName.expand('../config.ini');
console.debug(s);
//d:/dev/infinity/bin/config.ini
extract()¶
Strips path data and, optionally, the file extension leaving just the name of the file.
Signature:
extract( fileName: string, stripExtension?: boolean ): string
Parameters:
-
fileName:
string
The data to examine.
-
stripExtension:
boolean
, optionalWhether to strip the extension too.
Return type: string
Example:
infinity.loadModule('infinity.fileSystem');
let s = infinity.fileName.extract('c:/tmp/test.txt', true);
console.debug(s);
//test
extractDirectory()¶
Extracts path data from a file path string.
Signature:
extractDirectory( fileName: string ): string
Parameters:
- fileName:
string
The file path.
Return type: string
Example:
infinity.loadModule('infinity.fileSystem');
let s = infinity.fileName.extractDirectory('c:/tmp/test.txt');
console.debug(s);
//c:/tmp/
isValid()¶
Returns whether the given filename is a valid for the operating system.
Signature:
isValid( fileName: string ): boolean
Parameters:
- fileName:
string
The filename to be checked.
Return type: boolean
Example:
infinity.loadModule('infinity.fileSystem');
if ( infinity.fileName.isValid(fileName) ) {
//...
}
quote()¶
Puts if necessary double quotes around file names with spaces.
Signature:
quote( fileName: string ): string
Parameters:
- fileName:
string
The filename to be checked.
Return type: string
Example:
infinity.loadModule('infinity.fileSystem');
let path = infinity.fileName.quote('c:/tmp 2/test.txt');
console.debug(path);
//"c:/tmp 2/test.txt"