Walk a directory/Recursively: Difference between revisions
Content added Content deleted
(Added Emacs Lisp Example) |
(Add Swift implementation.) |
||
Line 1,982: | Line 1,982: | ||
f displayNl |
f displayNl |
||
].</lang> |
].</lang> |
||
=={{header|Swift}}== |
|||
{{works with|Swift|3.0}} |
|||
<lang swift>import Foundation |
|||
let fileSystem = FileManager.default |
|||
let rootPath = "/" |
|||
// Enumerate the directory tree (which likely recurses internally)... |
|||
if let fsTree = fileSystem.enumerator(atPath: rootPath) { |
|||
while let fsNodeName = fsTree.nextObject() as? NSString { |
|||
let fullPath = "\(rootPath)/\(fsNodeName)" |
|||
var isDir: ObjCBool = false; |
|||
fileSystem.fileExists(atPath: fullPath, isDirectory: &isDir) |
|||
if !isDir.boolValue && fsNodeName.pathExtension == "txt" { |
|||
print(fsNodeName) |
|||
} |
|||
} |
|||
}</lang> |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |