邮编批处理文件夹 [英] Zip a folder in batch

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

问题描述

我有事情,比如文本文件:

 %USERPROFILE%/桌面/ FileFolder1
%USERPROFILE%/桌面/ FileFolder2
%USERPROFILE%/桌面/ FileFolder3

等。
我希望它把每一个这些文件夹和zip他们。然后我需要它来移动压缩到一个特定的目录(E:/),我希望它把版本号(1.0,1.1,1.2等),如果盘片没有足够的空间,然后返回一个错误,如

  echo.Error:光盘上没有足够的空间。

和工作时:

  echo.Success。
暂停
出口

所以,如果我跑了两次盘应该有:

  E:/ FileFolder1 1.0.zip
E:/ FileFolder2 1.0.zip
E:/ FileFolder3 1.0.zip
E:/ FileFolder1 1.1.zip
E:/ FileFolder2 1.1.zip
E:/ FileFolder3 1.1.zip

只要它不是太大。这就是所有我想做的事情。
注:我将手动添加文件夹到文本文件

FYI我曾尝试研究和一切要么insanly长或我要下载一些扩展包或什么的。

编辑:我也想:

  echo.Error:没有光盘插入。

,如果没有光盘插入


解决方案

  1. 要遍历一个文本文件的内容,阅读的帮助和实验与...命令行

      FOR / F令牌= *%A IN(file.txt的)DO @ECHO%一


  2. 有关设置增量文件名,尝试在一个循环的计数器。阅读 HELP SET 和试验

     一套CNT = 0
    :再次
    集/一个CNT + = 1
    如果存在%DEST%\\%名称%%CNT %%分机%转到:再次
    回声副本%SRC%%DEST%\\%名称%。%CNT %%分机%


  3. 检查,如果磁盘插入你可能想尝试

     如果存在的E:\\ NUL ECHO E:\\存在!


  4. 要检查是否有磁盘足够的可用空间,您可以使用 WMIC 。与 FINDSTR 的输出,而管的结果过滤器与一个 A变量。实验..

      FOR / F标记= 1%I IN('WMIC逻辑磁盘得到名称^,^自由空间| FINDSTR / IE:')DO @echo免费=%I

    ,然后检查文件是否符合,其中〜z修饰符是该文件的大小,请参阅 HELP CALL 的previous命令的结果(比较解释),并尝试

      IF%免费%GEQ%〜Z1 ECHO%1在电子商务适合:[%免费%^>%〜Z1]


我留下作为一个练习给你,把所有这些拼凑的方式。

I have a text file with things like:

%userprofile%/Desktop/FileFolder1
%userprofile%/Desktop/FileFolder2
%userprofile%/Desktop/FileFolder3

ect. and i want it to take each of those folders and zip them. then i need it to move the zip to a specific directory (E:/) and I want it to put the version number (1.0, 1.1, 1.2 ect) and if the disc doesn't have enough space then return an error such as:

echo.Error: Not enough space on disc.

and when it works:

echo.Success.
pause
exit

so if i run it twice the disc should have:

E:/FileFolder1 1.0.zip
E:/FileFolder2 1.0.zip
E:/FileFolder3 1.0.zip
E:/FileFolder1 1.1.zip
E:/FileFolder2 1.1.zip
E:/FileFolder3 1.1.zip

as long as it's not too large. So that's about all I want it to do. Note: I'll manually add folders to the text file.

FYI I did try to research and everything was either insanly long or i have to download some extension pack or whatever.

EDIT: also I want:

echo.Error: No disc inserted.

if there is no disc inserted.

解决方案

  1. To iterate over the contents of a text file, read HELP FOR and experiment in a command line with...

    FOR /F "tokens=*" %a IN (file.txt) DO @ECHO %a
    

  2. For setting an incremental filename, try a counter in a loop. Read HELP SET and experiment with

    set cnt=0
    :again
    set /a cnt+=1
    if exist %dest%\%name%.%cnt%%ext% goto :again
    echo copy %src% %dest%\%name%.%cnt%%ext%
    

  3. for checking if the disk is inserted you might want to try

    IF EXIST E:\NUL ECHO E:\ exists!
    

  4. to check if there is enough free space in the disk, you may use wmic. Filter the output with findstr, and "pipe" the result to a variable with a FOR. Experiment with..

    FOR /F "tokens=1" %i IN ('wmic logicaldisk get name^,freespace^|findstr /I "E:"') Do @echo free = %i
    

    and then to check if a file fits, compare the result of the previous command with the file's size, see HELP CALL (where the ~z modifier is explained), and try

     IF %free% GEQ %~z1 ECHO %1 fits in E: [%free%^>%~z1]
    

I leave as an exercise to you the way to put all this pieces together.

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

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