structure Converter = struct fun endsWithDsc str = if String.size str >= 4 then let val size = String.size str val expectedExtension = String.substring (str, size - 4, 4) in expectedExtension = ".dsc" end else false fun convertFile path = () fun loop (dir, rootPath) = case OS.FileSys.readDir dir of SOME path => let val folderPath = String.concat [rootPath, "/", path] val () = print (folderPath ^ "\n") val () = if OS.FileSys.isDir folderPath then (* handle recursive directory *) let val newDir = OS.FileSys.openDir folderPath in loop (newDir, folderPath) end else if OS.FileSys.isLink folderPath then (* ignore *) () else if endsWithDsc path then (* is a file ending with .dsc extension *) convertFile folderPath else (* is a file but doesn't end with .dsc, so ignore *) () in loop (dir, rootPath) end | NONE => OS.FileSys.closeDir dir fun main () = let val path = OS.FileSys.getDir () val dir = OS.FileSys.openDir path in loop (dir, path) end end