# File

The `File` class is designed to handle file-related operations, providing methods for managing file properties and interactions.

### Constructor

#### `constructor(filePath: String)`

Creates an instance of the `File` class representing a specific file path.

* `filePath` (String): The file path for which the `File` instance is created.

### Methods

* **getAbsolutePath(): String**

Retrieves the absolute path of the file, including the file's name.

```java
var absolutePath = file.getAbsolutePath();
```

* **exists(): Boolean**

Checks if the file exists and returns true if it exists, otherwise false.

```java
var fileExists = file.exists();
```

* **isFile(): Boolean**

Determines whether the object represents a file (as opposed to a directory) and returns true for a file, false otherwise.

```java
var isFile = file.isFile();
```

* **isDirectory(): Boolean**

Determines whether the object represents a directory and returns true for a directory, false otherwise.

```java
var isDirectory = file.isDirectory();
```

* **lastModified(): Long**

Gets the timestamp indicating the last modification time of the file, typically in milliseconds since the epoch. The return type is "Long."

```java
var lastModified = file.lastModified();
```

* **delete(): Boolean**

Attempts to delete the file and returns true if the deletion was successful, and false if it failed.

```java
var deletionSuccessful = file.delete();
```

* **getName(): String**

Retrieves the name of the file (without the path) as a string.

```java
var fileName = file.getName();
```

* **getParent(): String**

Gets the parent directory's path as a string.

```java
var parentDirectory = file.getParent();
```

* **getParentFile(): File**

Returns a new File object representing the parent directory of the current file.

```java
var parentDirectoryFile = file.getParentFile();
```

* **getPath(): String**

Retrieves the path of the file (including its name) as a string.

```java
var filePathString = file.getPath();
```

For a more comprehensive overview, you can explore the [FileUtil](/scripting/utilities/fileutil.md) class to delve into the full range of available methods.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.b2winsuite.com/scripting/types-and-objects/objects/file.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
