没有根文件夹的 Zip 压缩
Zip compress without root folders
我的问题是我必须使用 linux zip 控制台命令生成一个 zip 文件。我的命令如下:
zip -r /folder1/folder2/EXP_45.zip /folder1/folder2/EXP_45/
returns 一个正确的 zip,只包含我想要的根文件夹:
Returns
EXP_45.zip
-文件夹1
--文件夹2
---EXP_45
...
我要
EXP_45.zip
-EXP_45
...
EXP_45 是一个可以包含文件和文件夹的文件夹,它们必须存在于 zip 中。我只希望树结构以 EXP_45 文件夹开始。
有什么解决办法吗?
我需要它成为单个命令的原因是它是 PL SQL 函数中作业的一个动作,例如:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME=>'compress_files', --- job name
JOB_ACTION=>'/usr/bin/zip', --- executable file with path
JOB_TYPE=>'executable', ----- job type
NUMBER_OF_ARGUMENTS=>4, -- parameters in numbers
AUTO_DROP =>false,
CREDENTIAL_NAME=>'credentials' -- give credentials name which you have created before "credintial"
);
dbms_scheduler.set_job_argument_value('compress_files',1,'-r');
dbms_scheduler.set_job_argument_value('compress_files',2,'-m');
dbms_scheduler.set_job_argument_value('compress_files',3,'/folder1/folder2/EXP_45.zip');
dbms_scheduler.set_job_argument_value('compress_files',4,'/folder1/folder2/EXP_45/');
DBMS_SCHEDULER.RUN_JOB('compress_files');
END;
您想在创建 zip 文件时使用 -j
(或 --junk-paths
)选项。以下内容来自 zip 手册页。
-j
--junk-paths
Store just the name of a saved file (junk the path), and do not store directory names.
By default, zip will store the full path (relative to the current directory).
问题澄清后更新
为什么不将与下面代码等效的代码放入 shell 脚本中并获取 SQL 函数来调用它?您只需要将目录名称传递给 cd 和输出 zip 的名称即可。
cd folder1/folder2
zip -r /tmp/EXP_45.zip EXP_45
我无法使用 zip 找到解决此问题的方法,但我使用 jar 找到了它。命令将是:
jar cMf /folder1/folder2/EXP_45.zip -C /folder1/folder2/EXP_45 .
此外,在 pl sql 中使用工作的解决方案是:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME=>'compress_files', --- job name
JOB_ACTION=>'/usr/bin/jar', --- executable file with path
JOB_TYPE=>'executable', ----- job type
NUMBER_OF_ARGUMENTS=>5, -- parameters in numbers
AUTO_DROP =>false,
CREDENTIAL_NAME=>'credentials' -- give credentials name which you have created before "credintial"
);
dbms_scheduler.set_job_argument_value('compress_files',1,'cMf');
dbms_scheduler.set_job_argument_value('compress_files',2,'/folder1/folder2/EXP_45.zip');
dbms_scheduler.set_job_argument_value('compress_files',3,'-C');
dbms_scheduler.set_job_argument_value('compress_files',4,'/folder1/folder2/EXP_45');
dbms_scheduler.set_job_argument_value('compress_files',5,'.');
DBMS_SCHEDULER.RUN_JOB('compress_files');
END;
我的问题是我必须使用 linux zip 控制台命令生成一个 zip 文件。我的命令如下:
zip -r /folder1/folder2/EXP_45.zip /folder1/folder2/EXP_45/
returns 一个正确的 zip,只包含我想要的根文件夹:
Returns
EXP_45.zip
-文件夹1
--文件夹2
---EXP_45
...
我要
EXP_45.zip
-EXP_45
...
EXP_45 是一个可以包含文件和文件夹的文件夹,它们必须存在于 zip 中。我只希望树结构以 EXP_45 文件夹开始。
有什么解决办法吗?
我需要它成为单个命令的原因是它是 PL SQL 函数中作业的一个动作,例如:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME=>'compress_files', --- job name
JOB_ACTION=>'/usr/bin/zip', --- executable file with path
JOB_TYPE=>'executable', ----- job type
NUMBER_OF_ARGUMENTS=>4, -- parameters in numbers
AUTO_DROP =>false,
CREDENTIAL_NAME=>'credentials' -- give credentials name which you have created before "credintial"
);
dbms_scheduler.set_job_argument_value('compress_files',1,'-r');
dbms_scheduler.set_job_argument_value('compress_files',2,'-m');
dbms_scheduler.set_job_argument_value('compress_files',3,'/folder1/folder2/EXP_45.zip');
dbms_scheduler.set_job_argument_value('compress_files',4,'/folder1/folder2/EXP_45/');
DBMS_SCHEDULER.RUN_JOB('compress_files');
END;
您想在创建 zip 文件时使用 -j
(或 --junk-paths
)选项。以下内容来自 zip 手册页。
-j
--junk-paths
Store just the name of a saved file (junk the path), and do not store directory names.
By default, zip will store the full path (relative to the current directory).
问题澄清后更新
为什么不将与下面代码等效的代码放入 shell 脚本中并获取 SQL 函数来调用它?您只需要将目录名称传递给 cd 和输出 zip 的名称即可。
cd folder1/folder2
zip -r /tmp/EXP_45.zip EXP_45
我无法使用 zip 找到解决此问题的方法,但我使用 jar 找到了它。命令将是:
jar cMf /folder1/folder2/EXP_45.zip -C /folder1/folder2/EXP_45 .
此外,在 pl sql 中使用工作的解决方案是:
BEGIN
DBMS_SCHEDULER.CREATE_JOB (
JOB_NAME=>'compress_files', --- job name
JOB_ACTION=>'/usr/bin/jar', --- executable file with path
JOB_TYPE=>'executable', ----- job type
NUMBER_OF_ARGUMENTS=>5, -- parameters in numbers
AUTO_DROP =>false,
CREDENTIAL_NAME=>'credentials' -- give credentials name which you have created before "credintial"
);
dbms_scheduler.set_job_argument_value('compress_files',1,'cMf');
dbms_scheduler.set_job_argument_value('compress_files',2,'/folder1/folder2/EXP_45.zip');
dbms_scheduler.set_job_argument_value('compress_files',3,'-C');
dbms_scheduler.set_job_argument_value('compress_files',4,'/folder1/folder2/EXP_45');
dbms_scheduler.set_job_argument_value('compress_files',5,'.');
DBMS_SCHEDULER.RUN_JOB('compress_files');
END;