# GetFileInfo(string, FileInfoResult*)

> Gets information about a file.

## Definition

* **Type:** Method
* **Namespace:** [Unity.IO.LowLevel.Unsafe](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe.md)
* **Assembly:** UnityEngine.CoreModule

```csharp
public static ReadHandle GetFileInfo(string filename, FileInfoResult* result)
```

### Parameters

**** (\[string]\(https\://learn.microsoft.com/dotnet/api/system.string)): The name of the file to query.**** (\[FileInfoResult\*]\(/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/fileinforesult)): A struct that this function fills in with information about the file upon completion of this asynchronous request.

### Returns

| Type                                                                                 | Description                                                                                    |
| ------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
| [ReadHandle](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/readhandle.md) | A read handle that you can use to monitor the progress and status of this GetFileInfo command. |

### Remarks

This function gets information about the specified file asynchronously without opening the file. On completion of the asynchronous operation, the `result` parameter's [FileInfoResult.FileState](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/fileinforesult/filestate.md) member reports whether the file exists ([FileState.Exists](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/filestate/exists.md)) or not ([FileState.Absent](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/filestate/absent.md)). If the file exists, the `result` parameter's [FileInfoResult.FileSize](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/fileinforesult/filesize.md) member reports the size of the file in bytes. If the file doesn't exist, the size is reported as zero.

`GetFileInfo` does not copy `result`. It stores the pointer and writes the file information through it on a worker thread when the operation completes, which can be after the call returns. Keep the [FileInfoResult](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/fileinforesult.md) that `result` refers to valid and pinned until the returned [ReadHandle](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/readhandle.md) has a status other than [ReadStatus.InProgress](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/readstatus/inprogress.md). Otherwise, the garbage collector can move or free the memory before the write occurs. Until the operation completes, [FileInfoResult.FileState](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/fileinforesult/filestate.md) has its initial value of [FileState.Absent](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/filestate/absent.md), which is the same value that a missing file produces, so treat the result as final only after the handle completes.

**Warning:** A `fixed` statement around the `GetFileInfo` call pins the [FileInfoResult](/engine/6000.7/script-reference/unity/io/lowlevel/unsafe/fileinforesult.md) only for the duration of its block, not for the asynchronous operation that continues after the block exits. This is a common mistake in `async` methods, where the compiler places locals that outlive an `await` on the managed heap. Pin the memory for the whole operation.
