批处理文件脚本zip文件 [英] Batch file script to zip files

查看:181
本文介绍了批处理文件脚本zip文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这个模式的文件夹结构。我刚刚显示两个子目录和2个文件中的每个但一般我有一个单级子目录的n个和文件的单级(但可以是文件n个)下它们。

 主目录
子目录X:
  文件1
  文件2
目录Y:
  文件3
  文件4

我需要创建一个Windows脚本,批处理文件从主目录中运行,并给我两个zip文件x.zip和含有各自的文件y.zip。

我知道我的脚本必须使用和zip命令,但我会疯狂试图让它工作,我不能从这些命令的语法理解和谷歌搜索似乎没有帮助。

我发现像这样的命令在%F(*。*)做拉链%〜nf.zip%F,但它似乎只有当文件直接出现无子文件夹中工作。


解决方案

 对/天%%一个在(*)做(ECHO拉链-r -p%%〜呐。拉链\\ %%一个\\ *)

应该从一个批次内工作。

请注意,我已经包含了 ECHO 来简单地表明,提出的命令。你需要删除 ECHO keywor来执行这些命令。

i have a folder structure in this pattern. I've just shown two sub directories and 2 files in each but generally I have n number of subdirectories at a single level and single level of files (but can be n number of files)under them.

Directory master
subDirectory x:
  file1
  file2
Directory y:
  file 3
  file 4

I need to create a windows script, a batch file to run from the master directory and give me two zip files x.zip and y.zip containing their respective files.

I know my script has to use for and zip commands but I am going bonkers trying to get it to work as I can't understand from the syntax of these commands and googling doesnt seem to help.

I found a command like this for %f in ("*.*") do zip "%~nf.zip" "%f" but it seems to be working only if the files are directly there without subfolders.

解决方案

for /d %%a in (*) do (ECHO zip -r -p "%%~na.zip" ".\%%a\*")

should work from within a batch.

Note that I've included an ECHO to simply SHOW the command that is proposed. You'd need to remove the ECHO keywor to EXECUTE the commands.

这篇关于批处理文件脚本zip文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆