Skip to content

Instantly share code, notes, and snippets.

@Aidan-Huang
Last active August 29, 2015 14:15
Show Gist options
  • Save Aidan-Huang/83aab7d74357a16cd32c to your computer and use it in GitHub Desktop.
Save Aidan-Huang/83aab7d74357a16cd32c to your computer and use it in GitHub Desktop.
copy dir files for EnglishPod
import Cocoa
let folderPath = "/Users/admin/Downloads/1-30"
let newPath = "/Users/admin/tmp/"
let fileManager = NSFileManager.defaultManager()
let enumerator:NSDirectoryEnumerator = fileManager.enumeratorAtPath(folderPath)!
while let element = enumerator.nextObject() as? String {
if element.hasSuffix("dg.mp3") {
var fullElementPath = folderPath.stringByAppendingPathComponent(element)
println(fullElementPath)
let destPath = newPath.stringByAppendingPathComponent(element.lastPathComponent)
var err: NSError?
if NSFileManager.defaultManager().copyItemAtPath(fullElementPath, toPath: destPath, error: &err) {
println("\(fullElementPath) file added to the folder.")
} else {
println("FAILED to add \(fullElementPath) to the folder.")
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment