Skip to content

Commit

Permalink
Added utility methods for getting files date creation/modified
Browse files Browse the repository at this point in the history
  • Loading branch information
vashpan committed Nov 9, 2019
1 parent 0811eaf commit 2e341ee
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
4 changes: 4 additions & 0 deletions DevCleaner.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
71A21A0C20541BE800B55651 /* XcodeFiles.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A21A0B20541BE800B55651 /* XcodeFiles.swift */; };
71A21A0E20544CA300B55651 /* XcodeFileEntry.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71A21A0D20544CA300B55651 /* XcodeFileEntry.swift */; };
71AAD2A32316A99F00D6B133 /* dev-cleaner.sh in Resources */ = {isa = PBXBuildFile; fileRef = 71AAD2A22316A99F00D6B133 /* dev-cleaner.sh */; };
71AE37EF23776AFB009C03BB /* FileManager+DateProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71AE37EE23776AFB009C03BB /* FileManager+DateProperties.swift */; };
71B01E8E20824F2A00940041 /* XcodeEntryCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71B01E8D20824F2A00940041 /* XcodeEntryCellView.swift */; };
71B01E902082551000940041 /* SizeCellView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71B01E8F2082551000940041 /* SizeCellView.swift */; };
71C8ACDE20A4EC2200E7A13B /* Credits.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 71C8ACDD20A4EC2200E7A13B /* Credits.rtf */; };
Expand Down Expand Up @@ -93,6 +94,7 @@
71A21A0B20541BE800B55651 /* XcodeFiles.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeFiles.swift; sourceTree = "<group>"; };
71A21A0D20544CA300B55651 /* XcodeFileEntry.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeFileEntry.swift; sourceTree = "<group>"; };
71AAD2A22316A99F00D6B133 /* dev-cleaner.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = "dev-cleaner.sh"; sourceTree = "<group>"; };
71AE37EE23776AFB009C03BB /* FileManager+DateProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "FileManager+DateProperties.swift"; sourceTree = "<group>"; };
71B01E8D20824F2A00940041 /* XcodeEntryCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = XcodeEntryCellView.swift; sourceTree = "<group>"; };
71B01E8F2082551000940041 /* SizeCellView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SizeCellView.swift; sourceTree = "<group>"; };
71C8ACDD20A4EC2200E7A13B /* Credits.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = Credits.rtf; sourceTree = "<group>"; };
Expand Down Expand Up @@ -271,6 +273,7 @@
children = (
719B25DB205EF9D7007560C0 /* FileManager+DirectorySize.swift */,
716667CF221A26BA004D4FC4 /* FileManager+HomeFolder.swift */,
71AE37EE23776AFB009C03BB /* FileManager+DateProperties.swift */,
71E7F835214E8D4400A11601 /* URL+AcquireAccessFromSandbox.swift */,
71E7F839214E9A4300A11601 /* String+MD5.swift */,
);
Expand Down Expand Up @@ -422,6 +425,7 @@
71A21A0E20544CA300B55651 /* XcodeFileEntry.swift in Sources */,
714AB65F22DA87FA00A7FBB7 /* DeviceLogsFileEntry.swift in Sources */,
71012FAC230C928600FDF8ED /* CmdLine.swift in Sources */,
71AE37EF23776AFB009C03BB /* FileManager+DateProperties.swift in Sources */,
719B25D9205ECA53007560C0 /* Version.swift in Sources */,
71B01E8E20824F2A00940041 /* XcodeEntryCellView.swift in Sources */,
715E8C3D216566FD0059A2E5 /* Weak.swift in Sources */,
Expand Down
35 changes: 35 additions & 0 deletions DevCleaner/Utilities/Extensions/FileManager+DateProperties.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
//
// FileManager+DateProperties.swift
// DevCleaner
//
// Created by Konrad Kołakowski on 09/11/2019.
// Copyright © 2019 One Minute Games. All rights reserved.
//

import Foundation

extension FileManager {
func dateModified(for url: URL) -> Date {
guard let attrs = try? self.attributesOfItem(atPath: url.path) else {
return Date.distantPast
}

guard let result = attrs[.modificationDate] as? Date else {
return Date.distantPast
}

return result
}

func dateCreated(for url: URL) -> Date {
guard let attrs = try? self.attributesOfItem(atPath: url.path) else {
return Date.distantPast
}

guard let result = attrs[.creationDate] as? Date else {
return Date.distantPast
}

return result
}
}

0 comments on commit 2e341ee

Please sign in to comment.