     let currentURL = URL(string: address.replacingCharacters(in: address.range(of: "{#0}")!, with: "\(i)"))!
     dump("loading: \(currentURL)")
     let data = try! Data(contentsOf: currentURL)
-    let savePath = sourceDir.appendingPathComponent("text", isDirectory: true).appendingPathComponent(currentURL.lastPathComponent)
+    let savePath = textDir.appendingPathComponent(currentURL.lastPathComponent)
     dump("saving to: \(savePath)")
     try! data.write(to: savePath)
 }

    let currentImgURL = URL(string: imgAddress.replacingCharacters(in: imgAddress.range(of: "{#0}")!, with: "\(i)"))!
    dump("loading img: \(currentImgURL)")
    let data = try! Data(contentsOf: currentImgURL)
    let savePath = sourceDir.appendingPathComponent("images", isDirectory: true).appendingPathComponent(currentImgURL.lastPathComponent)
    dump("saving to: \(savePath)")
    try! data.write(to: savePath)
}

let resultDir = URL(fileURLWithPath: fm.currentDirectoryPath).appendingPathComponent("result", isDirectory: true)
checkDirExists(atPath: resultDir)
clearDirectory(atPath: resultDir)

let metaInfDirPath = resultDir.appendingPathComponent("META-INF")
dump("creating directory \(metaInfDirPath)")
try! fm.createDirectory(at: metaInfDirPath, withIntermediateDirectories: false, attributes: nil)
let metaInfFilePath = resultDir.appendingPathComponent("container.xml")
dump("creating file \(metaInfFilePath)")
try! containerXMLData().write(to: metaInfFilePath)

checkDirExists(atPath: sourceDir)
clearDirectory(atPath: sourceDir)

let resultDir = URL(fileURLWithPath: fm.currentDirectoryPath).appendingPathComponent("result", isDirectory: true)

checkDirExists(atPath: resultDir)
clearDirectory(atPath: resultDir)

let textDir = resultDir.appendingPathComponent("text")
let imgDir = resultDir.appendingPathComponent("images")

checkDirExists(atPath: textDir)
checkDirExists(atPath: imgDir)
