     if subDirectory.isEmpty {
         return path
     }
+    let subDirectory: String = {
+        return subDirectory.last == "/" ? subDirectory : subDirectory + "/"
+    }()
 
     return path.last == "/" ? path + subDirectory : path + "/" + subDirectory
+}
+
+/// Gets the folder from a path to a file. For example, supplying "/Users/name/file.txt" will
+/// return "/Users/name/"
+/// - Parameter path: String representing a path to a file
+/// - Returns: String representing the containing folder for the file
+func getFolderPathFromFilePath(_ path: String) -> String {
+    return path.replacingOccurrences(of: URL(fileURLWithPath: path).lastPathComponent, with: "")
 }
 
 

    let hasDiagnosticReportDataJsonPath: [JSONSubscriptType] = ["HasDiagnosticReportData"]
    let diagnosticReportFileNameJsonPath: [JSONSubscriptType] = ["DiagnosticReportFileName"]
    let uuidJsonPath: [JSONSubscriptType] = ["UUID"]

    let testableSummariesJsons = testSummariesPlistJson[testableSummariesJsonPath].arrayValue
    var totalTestsCount = 0
    var totalFailuresCount = 0
    for testableSummaryJson in testableSummariesJsons {
        let targetName = testableSummaryJson[targetNameJsonPath].stringValue
        let testSuitesJsons = testableSummaryJson.values(relativePath: testSuitesJsonPath)

        for testSuitesJson in testSuitesJsons {


    let testSuitesTestsAttr = XMLNode.attribute(withName: "tests", stringValue: String(totalTestsCount))  as! XMLNode
    let testSuitesFailuresAttr = XMLNode.attribute(withName: "failures", stringValue: String(totalFailuresCount)) as! XMLNode
    let testSuitesNameAttr = XMLNode.attribute(withName: "name", stringValue: "\(testDeviceName) \(testDeviceOSVersion)") as! XMLNode
    testSuitesNode.attributes = [testSuitesTestsAttr, testSuitesFailuresAttr, testSuitesNameAttr]

    // finally, save the xml report
    let xmlData = jUnitXml.xmlData(withOptions: Int(XMLNode.Options.nodePrettyPrint.rawValue))
