36 lines
809 B
Swift
Raw Normal View History

#!/usr/bin/swift
import Foundation
2019-10-23 05:21:21 +02:00
extension FileHandle : TextOutputStream {
public func write(_ string: String) {
2021-12-31 14:07:42 +03:00
if let data = string.data(using: .utf8) { self.write(data) }
2019-10-23 05:21:21 +02:00
}
}
2019-10-23 05:21:21 +02:00
var stderr = FileHandle.standardError
2021-12-31 14:07:42 +03:00
let manager = FileManager.default
2019-10-23 05:21:21 +02:00
var success = true
2021-12-31 14:07:42 +03:00
// The command line arguments given but without the script's name
let CMDLineArgs = Array(CommandLine.arguments.dropFirst())
for item in CMDLineArgs {
do {
let url = URL(fileURLWithPath: item)
var trashedPath: NSURL!
try manager.trashItem(at: url, resultingItemURL: &trashedPath)
print((trashedPath as URL).path, terminator: ":")
success = true
} catch {
print(item, terminator: ":", to: &stderr)
success = false
}
}
2019-10-23 05:21:21 +02:00
guard success else {
2021-12-31 14:07:42 +03:00
exit(1)
2019-10-23 05:21:21 +02:00
}