KMMergeTools.swift 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. //
  2. // KMMergeTools.swift
  3. // PDF Reader Pro
  4. //
  5. // Created by tangchao on 2023/2/4.
  6. //
  7. import Cocoa
  8. class KMMergeTools: NSObject {
  9. class func findAllFiles(folder: URL, result: inout [URL], types: [String] = []) {
  10. let fileManager = FileManager.default
  11. var isDirectory: ObjCBool = ObjCBool(false)
  12. fileManager.fileExists(atPath: folder.path, isDirectory: &isDirectory)
  13. if (!isDirectory.boolValue) {
  14. return
  15. }
  16. let contents = try?fileManager.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
  17. if contents == nil || contents?.count == 0 {
  18. return
  19. }
  20. var array = ["jpg","cur","bmp","jpeg","gif","png","tiff","tif",/*@"pic",*/"ico","icns","tga","psd","eps","hdr","jp2","jpc","pict","sgi","heic","pdf"]
  21. if types.count != 0 {
  22. array = types
  23. }
  24. for documentURL in contents! {
  25. var isDirectory: ObjCBool = ObjCBool(false)
  26. fileManager.fileExists(atPath: documentURL.path, isDirectory: &isDirectory)
  27. if (isDirectory.boolValue) {
  28. findAllFiles(folder: documentURL, result: &result, types: types)
  29. } else {
  30. if !array.contains(documentURL.pathExtension.lowercased()) {
  31. continue
  32. }
  33. result.append(documentURL)
  34. }
  35. }
  36. }
  37. }