 }
 
 func browseDir(pathBytes: [UInt8]) throws {
-  let fb = try FileBrowser(pathBytes: pathBytes)
-  while fb.next() {
-    count += 1
-    if fb.type == .D {
-      let nameBytes = fb.nameBytes
-      let len = nameBytes.count
-      if len <= 2 && nameBytes[0] == 46 && (len == 1 || nameBytes[1] == 46) {
-        // Ignore Dot file: . ..
-      } else {
-        var cp = [UInt8]()
-        cp.reserveCapacity(pathBytes.count + nameBytes.count + 1)
-        cp += pathBytes
-        cp.removeLast() // Remove null-byte 0
-        cp += nameBytes
-        cp.append(47)
-        cp.append(0) // Now append the trailing null-byte 0
-        try browseDir(cp)
-      }
-    }
-  }
-}
-
-func browseDir2(pathBytes: [UInt8]) throws {
-  let fb = try FileBrowser(pathBytes: pathBytes)
-  while fb.next() {
-    count += 1
-    if fb.type == .D {
-      var rn = fb.rawEntry.memory.d_name
-      try withUnsafePointer(&rn) { ptr in
-        let len = Int(Sys.strlen(UnsafePointer<CChar>(ptr)))
-        let b = UnsafeBufferPointer<UInt8>(start: UnsafePointer<UInt8>(ptr),
-            count: len)
-        if len <= 2 && b[0] == 46 && (len == 1 || b[1] == 46) {
+  do {
+    let fb = try FileBrowser(pathBytes: pathBytes)
+    while fb.next() {
+      count += 1
+      if fb.type == .D {
+        let nameBytes = fb.nameBytes
+        let len = nameBytes.count
+        if len <= 2 && nameBytes[0] == 46 && (len == 1 || nameBytes[1] == 46) {
           // Ignore Dot file: . ..
         } else {
           var cp = [UInt8]()
-          cp.reserveCapacity(pathBytes.count + len + 1)
+          cp.reserveCapacity(pathBytes.count + nameBytes.count + 1)
           cp += pathBytes
           cp.removeLast() // Remove null-byte 0
-          cp += b
+          cp += nameBytes
           cp.append(47)
           cp.append(0) // Now append the trailing null-byte 0
-          try browseDir2(cp)
-        }
-      }
-    }
+          try browseDir(pathBytes: cp)
+        }
+      }
+    }
+  } catch {
+    // Ignore in case of errors or denied permission.
+  }
+}
+
+func browseDir2(pathBytes: [UInt8]) throws {
+  do {
+    let fb = try FileBrowser(pathBytes: pathBytes)
+    while fb.next() {
+      count += 1
+      if fb.type == .D {
+        var rn = fb.rawEntry.pointee.d_name
+        try withUnsafePointer(&rn) { ptr in
+          let len = Int(Sys.strlen(sp: UnsafePointer<CChar>(ptr)))
+          let b = UnsafeBufferPointer<UInt8>(start: UnsafePointer<UInt8>(ptr),
+              count: len)
+          if len <= 2 && b[0] == 46 && (len == 1 || b[1] == 46) {
+            // Ignore Dot file: . ..
+          } else {
+            var cp = [UInt8]()
+            cp.reserveCapacity(pathBytes.count + len + 1)
+            cp += pathBytes
+            cp.removeLast() // Remove null-byte 0
+            cp += b
+            cp.append(47)
+            cp.append(0) // Now append the trailing null-byte 0
+            try browseDir2(pathBytes: cp)
+          }
+        }
+      }
+    }
+  } catch {
+    // Ignore in case of errors or denied permission.
   }
 }
 
 func peekDir(pathBytes: [UInt8]) {
   var pb = pathBytes
-  var store = [([UInt8], COpaquePointer)]()
+  var store = [([UInt8], OpaquePointer?)]()
   store.reserveCapacity(128)
   PATH: while store.count >= 0 { // Trick the compiler.
     let cap = UnsafePointer<CChar>(pb)

      }
    }
    DIRP: while store.count >= 0 { // Trick the compiler.
      var entry = readdir(dp)
      while entry != nil {
        count += 1
        if entry.memory.d_type == 4 {
          var dirName = entry.memory.d_name
          var ignore = true
          withUnsafePointer(&dirName) { ptr in
            let len = Int(Sys.strlen(UnsafePointer<CChar>(ptr)))
            let b = UnsafeBufferPointer<UInt8>(start: UnsafePointer<UInt8>(ptr),
                count: len)
            if len <= 2 && b[0] == 46 && (len == 1 || b[1] == 46) {

  var entry = readdir(dp)
  while entry != nil {
    count += 1
    if entry!.pointee.d_type == 4 {
      var dirName = entry!.pointee.d_name
      withUnsafePointer(&dirName) { ptr in
        let len = Int(Sys.strlen(sp: UnsafePointer<CChar>(ptr)))
        let b = UnsafeBufferPointer<UInt8>(start: UnsafePointer<UInt8>(ptr),
            count: len)
        if len <= 2 && b[0] == 46 && (len == 1 || b[1] == 46) {
