<!--
{
  "availability" : [
    "iOS: 2.0.0 - 2.0.0",
    "iPadOS: 2.0.0 - 2.0.0",
    "tvOS: 9.0.0 - 9.0.0",
    "visionOS: 1.0.0 - 1.0.0",
    "watchOS: 2.0.0 - 2.0.0"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileManager/fileAttributes(atPath:traverseLink:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager(im)fileAttributesAtPath:traverseLink:"
  },
  "title" : "fileAttributes(atPath:traverseLink:)"
}
-->

# fileAttributes(atPath:traverseLink:)

Returns a dictionary that describes the POSIX attributes of the file specified at a given.

```
func fileAttributes(atPath path: String, traverseLink yorn: Bool) -> [AnyHashable : Any]?
```

## Parameters

`path`

A file path.

`yorn`

If `path` is not a symbolic link, this parameter has no effect. If `path` is a symbolic link, then:

- If <doc://com.apple.documentation/documentation/Swift/true> the attributes of the linked-to file are returned, or if the link points to a nonexistent file the method returns `nil`.
- If <doc://com.apple.documentation/documentation/Swift/false>, the attributes of the symbolic link are returned.

## Return Value

An `NSDictionary` object that describes the POSIX attributes of the file specified at `path`. The keys in the dictionary are described in `File Attribute Keys`. If there is no item at `path`, returns `nil`.

## Discussion

This code example gets several attributes of a file and logs them.

```objc
NSFileManager *fileManager = [[NSFileManager alloc] init];
NSString *path = @"/tmp/List";
NSDictionary *fileAttributes = [fileManager fileAttributesAtPath:path traverseLink:YES];
 
if (fileAttributes != nil) {
    NSNumber *fileSize;
    NSString *fileOwner;
    NSDate *fileModDate;
    if (fileSize = [fileAttributes objectForKey:NSFileSize]) {
        NSLog(@"File size: %qi\n", [fileSize unsignedLongLongValue]);
    }
    if (fileOwner = [fileAttributes objectForKey:NSFileOwnerAccountName]) {
        NSLog(@"Owner: %@\n", fileOwner);
    }
    if (fileModDate = [fileAttributes objectForKey:NSFileModificationDate]) {
        NSLog(@"Modification date: %@\n", fileModDate);
    }
}
else {
    NSLog(@"Path (%@) is invalid.", path);
}
```

As a convenience, `NSDictionary` provides a set of methods (declared as a category in `NSFileManager.h`) for quickly and efficiently obtaining attribute information from the returned dictionary: [`fileGroupOwnerAccountName()`](/documentation/Foundation/NSDictionary/fileGroupOwnerAccountName()), [`fileModificationDate()`](/documentation/Foundation/NSDictionary/fileModificationDate()), [`fileOwnerAccountName()`](/documentation/Foundation/NSDictionary/fileOwnerAccountName()), [`filePosixPermissions()`](/documentation/Foundation/NSDictionary/filePosixPermissions()), [`fileSize()`](/documentation/Foundation/NSDictionary/fileSize()), [`fileSystemFileNumber()`](/documentation/Foundation/NSDictionary/fileSystemFileNumber()), [`fileSystemNumber()`](/documentation/Foundation/NSDictionary/fileSystemNumber()), and [`fileType()`](/documentation/Foundation/NSDictionary/fileType()). For example, you could rewrite the file modification statement in the code example above as:

```objc
if (fileModDate = [fileAttributes fileModificationDate])
    NSLog(@"Modification date: %@\n", fileModDate);
```

### Special Considerations

Because this method does not return error information, it has been deprecated as of OS X v10.5. Use [`attributesOfItem(atPath:)`](/documentation/Foundation/FileManager/attributesOfItem(atPath:)) instead.

## See Also

[`attributesOfItem(atPath:)`](/documentation/Foundation/FileManager/attributesOfItem(atPath:))

Returns the attributes of the item at a given path.

[`setAttributes(_:ofItemAtPath:)`](/documentation/Foundation/FileManager/setAttributes(_:ofItemAtPath:))

Sets the attributes of the specified file or directory.



---

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)