DolphinDB中是否有将文件压缩成Zip文件的内置函数?

huangapple go评论54阅读模式
英文:

Is there a built-in function in DolphinDB to compress files into a Zip file?

问题

以下是翻译好的部分:

我们在以下情景中使用DolphinDB:

  1. 回测分析(使用peach函数进行多种策略的分析)
  • 从分区表中提取基础数据
  • 执行回测
  • 将结果存储在数据库中
  • 将结果导出为CSV文件到临时目录
  • 压缩文件成Zip归档并将其存储在目标路径,即挂载在Docker容器上的远程NAS磁盘
  1. 查询计算结果

这是我的问题:DolphinDB中是否有内置函数可以将文件压缩成Zip文件?

英文:

We are using DolphinDB in the following scenarios:

  1. Backtesting analysis (using the peach function for multiple strategies)
  • extract basic data from partitioned tables
  • perform backtesting
  • store the results in the database
  • export the results as CSV files to a temporary directory
  • compress the files into a Zip archive and store it in the target path, i.e., a remote NAS disk mounted on the Docker container
  1. Query the calculation results

Here is my question: is there a built-in function in DolphinDB to compress files into a Zip file?

答案1

得分: 1

目前,内置的压缩功能仍在开发中。现在,您可以使用 shell 命令来调用系统的 zip 命令来压缩文件。请参考以下脚本:

// 压缩目录中的文件到一个 Zip 存档
def zipDirFiles(srcDir, destFile, isMoveSrcFile=false) {
    if (!exists(srcDir)) {
        throw '源目录不存在:' + srcDir;
    }
    
    if (isMoveSrcFile) {
        zipParams = "-rm1";
    } else {
        zipParams = "-r1";
    }
    
    cdCmd = 'cd "' + srcDir + '"';
    zipCmd = 'zip ' + zipParams + ' "' + destFile + '" *';
    
    retCode = shell(cdCmd + ' && ' + zipCmd);
    
    if (retCode != 0) {
        throw "压缩文件夹失败,代码:" + retCode;
    }
}

// 测试
srcDir, destFile, isMoveSrcFile = "/qirp/temp/", "/qirp/123.zip", true;
zipDirFiles(srcDir, destFile, isMoveSrcFile);

注意:以上是您提供的脚本的翻译。

英文:

Currently, a built-in compression function is still under development. Now you can use shell commands to invoke the system’s zip command to compress files. Refer to the following script:

// compress the files in a directory into a Zip archive
def zipDirFiles(srcDir, destFile, isMoveSrcFile=false) {
        if(!exists(srcDir)) {
                throw 'Source directory does not exist:' + srcDir;
        }

        if (isMoveSrcFile) {
                zipParams = "-rm1";
        } else {
                zipParams = "-r1";
        }
        
        cdCmd = 'cd "' + srcDir + '"';  // Quotation marks "" are used to handle spaces in the path.
        zipCmd = 'zip ' + zipParams + ' "' + destFile + '" *';  // Quotation marks "" are used to handle spaces in the path.
        retCode = shell(cdCmd + ' && ' + zipCmd);
        if(retCode != 0) {
                throw "Failed to compress folder,code:" + retCode;
        }
}
// test
srcDir, destFile, isMoveSrcFile = "/qirp/temp/", "/qirp/123.zip", true;
zipDirFiles(srcDir, destFile, isMoveSrcFile);

huangapple
  • 本文由 发表于 2023年7月6日 13:38:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76625794.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定