Created
October 11, 2019 08:39
-
-
Save 623637646/fd240fd6ecc0dc7864d33ee4b8459985 to your computer and use it in GitHub Desktop.
Verify BRD's files.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// main.swift | |
// CheckBRD | |
// | |
// Created by Yanni Wang on 11/10/19. | |
// Copyright © 2019 Yanni. All rights reserved. | |
// | |
import Foundation | |
struct File: CustomStringConvertible { | |
var description: String { | |
return "\(self.name).\(self.fileType)" | |
} | |
let url: URL | |
let name: String | |
let fileType: String | |
let size: UInt64 | |
} | |
func run(url: URL, files: inout [File]) -> Void { | |
var isDir : ObjCBool = false | |
if FileManager.default.fileExists(atPath: url.path, isDirectory:&isDir) { | |
if isDir.boolValue { | |
if !url.absoluteString.contains(".git") { | |
let fileURLs = try? FileManager.default.contentsOfDirectory(at: url, includingPropertiesForKeys: nil) | |
if let fileURLs = fileURLs { | |
for url in fileURLs { | |
run(url: url, files: &files) | |
} | |
} else { | |
print("error file: \(url)") | |
} | |
} | |
} else { | |
let dict = try! FileManager.default.attributesOfItem(atPath: url.path) as NSDictionary | |
let text2 = try? String(contentsOf: url, encoding: .utf8) | |
if text2 == nil { | |
files.append(File.init(url: url, name: url.deletingPathExtension().lastPathComponent, fileType: url.pathExtension, size: dict.fileSize())) | |
} | |
} | |
} else { | |
fatalError() | |
} | |
} | |
let documentsURL = URL.init(string: "/Users/yanni/Documents/breadwallet-ios")! | |
var files = [File]() | |
run(url: documentsURL, files: &files) | |
// | |
var filesSortBySize = files.sorted { (a, b) -> Bool in | |
return a.size > b.size | |
} | |
// | |
var filesSortByKind = [String: [File]]() | |
for file in files { | |
if filesSortByKind[file.fileType] == nil { | |
filesSortByKind[file.fileType] = [File]() | |
} | |
filesSortByKind[file.fileType]?.append(file) | |
} | |
let keys = filesSortByKind.keys.sorted(by: <) | |
// END | |
print("begin") | |
for file in filesSortBySize { | |
print("\(file.name).\(file.fileType)(\(Double(file.size) / 1024) kb) \(file.url) \n") | |
} | |
print("end") | |
//print("end:---- \()") | |
//print("end:---- \n \(keys.joined(separator: "\n"))") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment