     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 version = XMLElement(kind: .attribute)
    version.name = "version"
    version.stringValue = "1.0"
    version.kind
    package.addAttribute(version)
    
    let metadata = XMLElement(name: "metadata")

    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 = imgDir.appendingPathComponent(currentImgURL.lastPathComponent)
    dump("saving to: \(savePath)")
    try! data.write(to: savePath)
}

let metaInfDirPath = resultDir.appendingPathComponent("META-INF")
dump("creating directory \(metaInfDirPath)")
try! fm.createDirectory(at: metaInfDirPath, withIntermediateDirectories: false, attributes: nil)
let metaInfFilePath = metaInfDirPath.appendingPathComponent("container.xml")
dump("creating file \(metaInfFilePath)")
try! containerXMLData().write(to: metaInfFilePath)
let textContents = try! fm.contentsOfDirectory(at: textDir, includingPropertiesForKeys: nil, options: [])
let imgContents = try! fm.contentsOfDirectory(at: imgDir, includingPropertiesForKeys: nil, options: [])
let packageFilePath = resultDir.appendingPathComponent("content.opf")
dump("creating file \(packageFilePath)")
try! packageXMLData(withFileList: textContents.map { $0.lastPathComponent } + imgContents.map {$0.lastPathComponent}).write(to: packageFilePath)
