Skip to content

Instantly share code, notes, and snippets.

@drosenstark
Created August 3, 2023 15:16

Revisions

  1. drosenstark created this gist Aug 3, 2023.
    16 changes: 16 additions & 0 deletions URL+OpenInFilesApp.swift
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    // thanks to this thing!
    // https://www.macstories.net/ios/fs-bookmarks-a-shortcut-to-reopen-files-and-folders-directly-in-the-files-app/

    extension URL {
    func openParentDirectoryInFilesApp() {
    guard var components = URLComponents(url: self.deletingLastPathComponent(), resolvingAgainstBaseURL: false) else { return }

    components.scheme = "shareddocuments"

    guard let newURL = components.url else { return }

    if UIApplication.shared.canOpenURL(newURL) {
    UIApplication.shared.open(newURL)
    }
    }
    }