Skip to content

Commit b8a7bc5

Browse files
committed
[feat]: return to original files package
1 parent a349015 commit b8a7bc5

File tree

6 files changed

+80
-77
lines changed

6 files changed

+80
-77
lines changed

Package.resolved

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ let package = Package(
1212
targets: ["ScriptToolkit"]),
1313
],
1414
dependencies: [
15-
.package(url: "https://github.com/DanielCech/Files.git", from: "2.0.0"),
15+
.package(url: "https://github.com/JohnSundell/Files.git", from: "2.0.0"),
1616
.package(url: "https://github.com/kareman/SwiftShell.git", from: "4.0.0"),
1717
.package(url: "https://github.com/DanielCech/Moderator.git", from: "0.0.0")
1818
],

Sources/ScriptToolkit/FileExtension.swift

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,42 @@ public extension File {
5151
throw OperationError.renameFailed(self)
5252
}
5353
}
54+
55+
////////////////////////////////////////////////////////////////////////////////
56+
// MARK: - Modification date
57+
58+
public func modificationDate() throws -> Date {
59+
60+
let fileAttributes = try FileManager.default.attributesOfItem(atPath: path) as [FileAttributeKey: Any]
61+
let modificationDate = fileAttributes[.modificationDate] as! Date
62+
63+
return modificationDate
64+
}
65+
66+
////////////////////////////////////////////////////////////////////////////////
67+
// MARK: - Tag file
68+
69+
public func tag(copy: Bool) throws {
70+
let date = try modificationDate()
71+
let suffix = ScriptToolkit.dateFormatter.string(from: date)
72+
for letter in "abcdefghijklmnopqrstuvwxyz" {
73+
74+
let file = try File(path: path)
75+
let newPath = (file.parent?.path ?? "./")
76+
let newName = file.nameExcludingExtension + "(\(suffix + String(letter)))" + "." + (file.extension ?? "")
77+
78+
if !FileManager.default.fileExists(atPath: newPath + newName) {
79+
if copy {
80+
try file.createDuplicate(withName: newName)
81+
}
82+
else {
83+
try file.rename(to: newName)
84+
}
85+
return
86+
}
87+
}
88+
}
89+
5490

5591
////////////////////////////////////////////////////////////////////////////////
5692
// MARK: - Photo Processing

Sources/ScriptToolkit/FileSystemItemExtension.swift

Lines changed: 0 additions & 73 deletions
This file was deleted.

Sources/ScriptToolkit/FolderExtension.swift

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,45 @@ public extension Folder {
4040
}
4141
}
4242

43+
////////////////////////////////////////////////////////////////////////////////
44+
// MARK: - Modification date
45+
46+
public func modificationDate() throws -> Date {
47+
48+
let fileAttributes = try FileManager.default.attributesOfItem(atPath: path) as [FileAttributeKey: Any]
49+
let modificationDate = fileAttributes[.modificationDate] as! Date
50+
51+
return modificationDate
52+
}
53+
54+
////////////////////////////////////////////////////////////////////////////////
55+
// MARK: - Tag folder
56+
57+
public func tag(copy: Bool) throws {
58+
let date = try modificationDate()
59+
let suffix = ScriptToolkit.dateFormatter.string(from: date)
60+
for letter in "abcdefghijklmnopqrstuvwxyz" {
61+
62+
let folder = try Folder(path: path)
63+
let newPath = (folder.parent?.path ?? "./")
64+
var newName = folder.nameExcludingExtension + "(\(suffix + String(letter)))"
65+
66+
if let ext = folder.extension {
67+
newName += "." + ext
68+
}
69+
70+
if !FileManager.default.fileExists(atPath: newPath + newName) {
71+
if copy {
72+
try folder.createDuplicate(withName: newName)
73+
}
74+
else {
75+
try folder.rename(to: newName)
76+
}
77+
return
78+
}
79+
}
80+
}
81+
4382
////////////////////////////////////////////////////////////////////////////////
4483
// MARK: - Flatten folder structure
4584

Sources/ScriptToolkit/ScriptToolkit.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import SwiftShell
1212
public enum ScriptError: Error {
1313
case fileExists
1414
case fileNotFound
15+
case moreInfoNeeded
1516
}
1617

1718
public struct ScriptToolkit {

0 commit comments

Comments
 (0)