<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: 9.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Foundation",
  "identifier" : "/documentation/Foundation/FileManager/removeItem(at:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "Foundation"
    ],
    "preciseIdentifier" : "c:objc(cs)NSFileManager(im)removeItemAtURL:error:"
  },
  "title" : "removeItem(at:)"
}
-->

# removeItem(at:)

Removes the file or directory at the specified URL.

```
func removeItem(at URL: URL) throws
```

## Parameters

`URL`

A file URL specifying the file or directory to remove. If the URL specifies a directory, the contents of that directory are recursively removed. You may specify `nil` for this parameter in Objective-C.

## Discussion

Prior to removing each item, the file manager asks its delegate if it should actually do so. It does this by calling the [`fileManager(_:shouldRemoveItemAt:)`](/documentation/Foundation/FileManagerDelegate/fileManager(_:shouldRemoveItemAt:)) method; if that method is not implemented (or the process is running in OS X 10.5 or earlier) it calls the [`fileManager(_:shouldRemoveItemAtPath:)`](/documentation/Foundation/FileManagerDelegate/fileManager(_:shouldRemoveItemAtPath:)) method instead. If the delegate method returns <doc://com.apple.documentation/documentation/Swift/true>, or if the delegate does not implement the appropriate methods, the file manager proceeds to remove the file or directory. If there is an error removing an item, the file manager may also call the delegate’s [`fileManager(_:shouldProceedAfterError:removingItemAt:)`](/documentation/Foundation/FileManagerDelegate/fileManager(_:shouldProceedAfterError:removingItemAt:)) or [`fileManager(_:shouldProceedAfterError:removingItemAtPath:)`](/documentation/Foundation/FileManagerDelegate/fileManager(_:shouldProceedAfterError:removingItemAtPath:)) method to determine how to proceed.

Removing an item also removes all old versions of that item, invalidating any URLs returned by the [`url(forPublishingUbiquitousItemAt:expiration:)`](/documentation/Foundation/FileManager/url(forPublishingUbiquitousItemAt:expiration:)) method to old versions.

---

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)