@@ -26,7 +26,7 @@ struct FileIterator: Sequence, IteratorProtocol {
26
26
var dirIterator : FileManager . DirectoryEnumerator ? = nil
27
27
28
28
/// Keep track of the current directory we're recursing through.
29
- var currentDirectory : String = " "
29
+ var currentDirectory = URL ( fileURLWithPath : " " )
30
30
31
31
/// Keep track of paths we have visited to prevent duplicates.
32
32
var visited : Set < String > = [ ]
@@ -54,7 +54,7 @@ struct FileIterator: Sequence, IteratorProtocol {
54
54
if FileManager . default. fileExists ( atPath: next, isDirectory: & isDir) {
55
55
if isDir. boolValue {
56
56
dirIterator = FileManager . default. enumerator ( atPath: next)
57
- currentDirectory = next
57
+ currentDirectory = URL ( fileURLWithPath : next, isDirectory : true )
58
58
} else { output = next }
59
59
} else {
60
60
// If a path doesn't exist, allow it pass down into the SwiftFormat API so it can throw
@@ -74,12 +74,13 @@ struct FileIterator: Sequence, IteratorProtocol {
74
74
while output == nil {
75
75
var isDir : ObjCBool = false
76
76
if let item = dirIterator? . nextObject ( ) as? String {
77
- if item. hasSuffix ( fileSuffix)
78
- && FileManager . default. fileExists (
79
- atPath: currentDirectory + " / " + item, isDirectory: & isDir)
80
- && !isDir. boolValue
81
- {
82
- output = currentDirectory + " / " + item
77
+ if item. hasSuffix ( fileSuffix) {
78
+ let absoluteItemPath = currentDirectory. appendingPathComponent ( item) . path
79
+ if FileManager . default. fileExists ( atPath: absoluteItemPath, isDirectory: & isDir)
80
+ && !isDir. boolValue
81
+ {
82
+ output = absoluteItemPath
83
+ }
83
84
}
84
85
} else { break }
85
86
}
0 commit comments