- Qbs Manual
- List of Built-in Services
- FileInfo Service
- Qbs 3.3.1

# FileInfo Service

The `FileInfo` service offers various operations on file paths, such as turning absolute paths into relative ones, splitting a path into its components, and so on.

## Available Operations

### baseName

     FileInfo.baseName(filePath: string): string

Returns the file name of `filePath` up to (but not including) the first '.' character.

### canonicalPath

     FileInfo.canonicalPath(filePath: string): string

Returns a canonicalized `filePath`, i.e. an absolute path without symbolic links or redundant "." or ".." elements. On Windows, drive substitutions are also resolved.

It is recommended to use `canonicalPath` in only those cases where canonical paths are really necessary. In most cases, `cleanPath` should be enough.

### cleanPath

     FileInfo.cleanPath(filePath: string): string

Returns `filePath` without redundant separators and with resolved occurrences of `.` and `..` components. For instance, `/usr/local//../bin/` becomes `/usr/bin`.

### completeBaseName

     FileInfo.completeBaseName(filePath: string): string

Returns the file name of `filePath` up to (but not including) the last '.' character.

### completeSuffix

     FileInfo.completeSuffix(filePath: string): string

Returns the file suffix of `filePath` from (but not including) the last '.' character.

This function was introduced in version 1.12.

### fileName

     FileInfo.fileName(filePath: string): string

Returns the last component of `filePath`, that is, everything after the last '/' character.

### fromNativeSeparators

     FileInfo.fromNativeSeparators(filePath: string): string

On Windows hosts, this function behaves the same as fromWindowsSeparators. On other operating systems, it returns the input unmodified.

### fromWindowsSeparators

     FileInfo.fromWindowsSeparators(filePath: string): string

Returns `filePath` with all '\' characters replaced by '/'.

### isAbsolutePath

     FileInfo.isAbsolutePath(filePath: string, hostOS?: string[]): boolean

Returns true if `filePath` is an absolute path and false if it is a relative one. If `hostOS` is specified, treats `filePath` as a file path of the kind found on that platform. This parameter defaults to the host OS on which Qbs is running and should normally be omitted.

### joinPaths

     FileInfo.joinPaths(...paths: string[]): string

Concatenates the given paths using the '/' character.

### path

     FileInfo.path(filePath: string, hostOS?: string[]): string

Returns the part of `filePath` that is not the file name, that is, everything up to (but not including) the last '/' character. If `filePath` is just a file name, then '.' is returned. If `filePath` ends with a '/' character, then the file name is assumed to be empty for the purpose of the above definition. If `hostOS` is specified, treats `filePath` as a file path of the kind found on that platform. This parameter defaults to the host OS on which Qbs is running and should normally be omitted.

### relativePath

     FileInfo.relativePath(dirPath: string, filePath: string): string

Returns a relative path so that joining `dirPath` and the returned path results in `filePath`. If necessary, '..' components are inserted. The function assumes `dirPath` and `filePath` to be absolute paths and `dirPath` to be a directory.

### suffix

     FileInfo.suffix(filePath: string): string

Returns the file suffix of `filePath` from (but not including) the first '.' character.

This function was introduced in version 1.12.

### toNativeSeparators

     FileInfo.toNativeSeparators(filePath: string): string

On Windows hosts, this function behaves the same as toWindowsSeparators. On other operating systems, it returns the input unmodified.

### toWindowsSeparators

     FileInfo.toWindowsSeparators(filePath: string): string

Returns `filePath` with all '/' characters replaced by '\'.

### pathListSeparator

     FileInfo.pathListSeparator(): string

Returns the host operating system separator for a path list that is used in environment variables or other contexts.

This function was introduced in version 1.22.

### pathSeparator

     FileInfo.pathSeparator(): string

Returns the host operating system path separator.

This function was introduced in version 1.22.

### executableSuffix

     FileInfo.executableSuffix(): string

Returns the host operating system executable suffix.

This function was introduced in version 1.23.