Last active
August 26, 2015 06:02
-
-
Save vy-let/ea305606ff208bf3ddeb to your computer and use it in GitHub Desktop.
For moving something to the trash from the command line, instead of rm'ing it.
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
// | |
// trash.swift | |
// For moving something to the trash from the command line | |
// (instead of rm'ing it). | |
// | |
// Created by Violet Baddley on 2015-8-25. | |
// Copyright © 2015 Violet Baddley. All rights reserved. | |
// Provided under the 2-Clause BSD License. | |
// | |
import Foundation | |
let effectiveArguments = Process.arguments[1..<Process.arguments.count] | |
let trashFiles = effectiveArguments.map { NSURL.fileURLWithPath($0) } | |
for tf in trashFiles { | |
do { | |
try NSFileManager.defaultManager().trashItemAtURL(tf, resultingItemURL: nil) | |
} catch let delError as NSError { | |
if let tfrp = tf.relativePath { | |
print("Couldn’t trash \(tfrp): \(delError.localizedDescription)") | |
} else { | |
print("Couldn’t trash a file because it hasn’t a valid path.") | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment