1234567891011121314151617181920212223242526272829303132333435363738394041424344 |
- //
- // KMMergeTools.swift
- // PDF Master
- //
- // Created by tangchao on 2023/2/4.
- //
- import Cocoa
- class KMMergeTools: NSObject {
-
- class func findAllFiles(folder: URL, result: inout [URL], types: [String] = []) {
- let fileManager = FileManager.default
- var isDirectory: ObjCBool = ObjCBool(false)
- fileManager.fileExists(atPath: folder.path, isDirectory: &isDirectory)
- if (!isDirectory.boolValue) {
- return
- }
-
- let contents = try?fileManager.contentsOfDirectory(at: folder, includingPropertiesForKeys: nil)
- if contents == nil || contents?.count == 0 {
- return
- }
-
- var array = ["jpg","cur","bmp","jpeg","gif","png","tiff","tif",/*@"pic",*/"ico","icns","tga","psd","eps","hdr","jp2","jpc","pict","sgi","heic","pdf"]
- if types.count != 0 {
- array = types
- }
- for documentURL in contents! {
- var isDirectory: ObjCBool = ObjCBool(false)
- fileManager.fileExists(atPath: documentURL.path, isDirectory: &isDirectory)
- if (isDirectory.boolValue) {
- findAllFiles(folder: documentURL, result: &result, types: types)
- } else {
- if !array.contains(documentURL.pathExtension.lowercased()) {
- continue
- }
-
- result.append(documentURL)
- }
- }
- }
- }
|