node js 解压rar格式文件

 

nodejs调用WinRAR解压

var cp = require("child_process");

function unZIP(winRarPath, password, zipFilePath, unZipFolder) {
    return new Promise(async (resolve, reject) => {
        cp.execFile(winRarPath, ["x", "-inul", `-p${password}`, zipFilePath, unZipFolder], function (err, stdout, stderr) {
            if (err) {
                reject(err)
            }
            resolve(stdout)
        })
    })
}
async function main(){
    try {
        let result = await unZIP("C:\\Program Files\\WinRAR\\WinRAR.exe", '111111', "D:\\test\\新建文本文档.rar", "D:\\test");
        console.log('解压成功')
    } catch (error) {
        console.log(error)
    }
}
main()

 

posted @ 2022-07-13 19:52  浅绿色i  阅读(722)  评论(0编辑  收藏  举报