英文:
Is there a built-in function in DolphinDB to compress files into a Zip file?
问题
以下是翻译好的部分:
我们在以下情景中使用DolphinDB:
- 回测分析(使用
peach
函数进行多种策略的分析)
- 从分区表中提取基础数据
- 执行回测
- 将结果存储在数据库中
- 将结果导出为CSV文件到临时目录
- 压缩文件成Zip归档并将其存储在目标路径,即挂载在Docker容器上的远程NAS磁盘
- 查询计算结果
这是我的问题:DolphinDB中是否有内置函数可以将文件压缩成Zip文件?
英文:
We are using DolphinDB in the following scenarios:
- 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
- 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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论