- Qbs Manual
- File Service
- Qbs 2.1.1

# File Service

The `File` service offers limited access to the file system for operations such as copying or removing files.

## Available Operations

### copy

     File.copy(sourceFilePath: string, targetFilePath: string): boolean

Copies `sourceFilePath` to `targetFilePath`. Any directory components in `targetFilePath` that do not yet exist will be created. If `sourceFilePath` is a directory, a recursive copy will be made. If an error occurs, a JavaScript exception will be thrown.

Note: `targetFilePath` must be the counterpart of `sourceFilePath` at the new location, not the new parent directory. This allows the copy to have a different name and is true even if `sourceFilePath` is a directory.

Note: The file is not copied if the source file timestamp is older than the destination file timestamp. If you want to replace the newer file, you need to remove it first via File.remove().

### exists

     File.exists(filePath: string): boolean

Returns true if and only if there is a file at `filePath`.

### directoryEntries

     File.directoryEntries(path: string, filter: File.Filter): string[]

Returns a sorted list of the directory `path`'s contents non-recursively, filtered by `filter`. The values of `filter` are equivalent to Qt's `QDir::Filter`.

### lastModified

     File.lastModified(filePath: string): number

Returns the time of last modification for the file at `filePath`. The concrete semantics of the returned value are platform-specific. You should only rely on the property that a smaller value indicates an older timestamp.

### makePath

     File.makePath(path: string): boolean

Makes the directory at `path`, creating intermediate directories if necessary. Conceptually equivalent to `mkdir -p`

### move

     File.move(oldPath: string, newPath: string, overwrite: boolean = true): boolean

Renames the file `oldPath` to `newPath`. Returns `true` if successful; otherwise returns `false`. If a file with the name `newPath` already exists, and `overwrite` is `false`, `move()` returns `false` (that is, the file will not be overwritten).

### remove

     File.remove(filePath: string): boolean

Removes the file at `filePath`. In case of a directory, it will be removed recursively.