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

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

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 命令来压缩文件。请参考以下脚本:

  1. // 压缩目录中的文件到一个 Zip 存档
  2. def zipDirFiles(srcDir, destFile, isMoveSrcFile=false) {
  3. if (!exists(srcDir)) {
  4. throw '源目录不存在:' + srcDir;
  5. }
  6. if (isMoveSrcFile) {
  7. zipParams = "-rm1";
  8. } else {
  9. zipParams = "-r1";
  10. }
  11. cdCmd = 'cd "' + srcDir + '"';
  12. zipCmd = 'zip ' + zipParams + ' "' + destFile + '" *';
  13. retCode = shell(cdCmd + ' && ' + zipCmd);
  14. if (retCode != 0) {
  15. throw "压缩文件夹失败,代码:" + retCode;
  16. }
  17. }
  18. // 测试
  19. srcDir, destFile, isMoveSrcFile = "/qirp/temp/", "/qirp/123.zip", true;
  20. 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:

  1. // compress the files in a directory into a Zip archive
  2. def zipDirFiles(srcDir, destFile, isMoveSrcFile=false) {
  3.         if(!exists(srcDir)) {
  4.                 throw 'Source directory does not exist:' + srcDir;
  5.         }
  6.         if (isMoveSrcFile) {
  7.                 zipParams = "-rm1";
  8.         } else {
  9.                 zipParams = "-r1";
  10.         }
  11.         
  12.         cdCmd = 'cd "' + srcDir + '"';  // Quotation marks "" are used to handle spaces in the path.
  13.         zipCmd = 'zip ' + zipParams + ' "' + destFile + '" *';  // Quotation marks "" are used to handle spaces in the path.
  14.         retCode = shell(cdCmd + ' && ' + zipCmd);
  15.         if(retCode != 0) {
  16.                 throw "Failed to compress foldercode:" + retCode;
  17.         }
  18. }
  19. // test
  20. srcDir, destFile, isMoveSrcFile = "/qirp/temp/", "/qirp/123.zip", true;
  21. 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:

确定