<!--
{
  "availability" : [
    "iOS: 8.0.0 -",
    "iPadOS: 8.0.0 -",
    "macCatalyst: 13.0.0 -",
    "macOS: 10.10.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Swift",
  "identifier" : "/documentation/Swift/file()",
  "metadataVersion" : "0.1.0",
  "role" : "Macro",
  "symbol" : {
    "kind" : "Macro",
    "modules" : [
      "Swift"
    ],
    "preciseIdentifier" : "s:s4filexycs26ExpressibleByStringLiteralRzlufm"
  },
  "title" : "file()"
}
-->

# file()

Produces the path to the file in which it appears.

```
@freestanding(expression) macro file<T>() -> T where T : ExpressibleByStringLiteral
```

## Overview

The string value from `#file` depends on the language version,
to enable migration from the old `#filePath` behavior
to the new `#fileID` behavior.
Currently, `#file` has the same value as `#filePath`.
In a future version of Swift,
`#file` will have the same value as `#fileID` instead.
To adopt the future behavior,
replace `#file` with `#fileID` or `#filePath` as appropriate.

This macro’s value can be changed by `#sourceLocation`,
as described in [Line Control Statement](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/statements#Line-Control-Statement) in [The Swift Programming Language](https://docs.swift.org/swift-book/).

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)