如何在批处理脚本中压缩多个.txt文件 [英] how to compress multiple .txt files in batch script

查看:98
本文介绍了如何在批处理脚本中压缩多个.txt文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何批量压缩文件夹中的多个文本文件不想要使用任何其他工具



我正在尝试这个

CD C:\ Users \Documents \ArchiveUp

/(%。TXT)中的/ R %% G执行7za a -t7z%% G%%〜 nG.7z





i对我不起作用。

任何人都可以帮助我?

how to zip multiple text files in a folder in batch dont want want to use any other tools

i'm trying this
CD C:\Users\Documents\ArchiveUp
For /R %%G in (*.TXT) do 7za a -t7z "%%G" "%%~nG.7z"


i didnt work for me.
Could any one help me?

推荐答案

请参阅我对该问题的评论。您缺少具有ZIP功能的应用程序或命令。



因此,第一种方法是拥有此类应用程序。我建议,首先,开源7-Zip:

https:// en。 wikipedia.org/wiki/7-Zip [ ^ ],

http://www.7-zip.org/ [ ^ ]。



令人惊讶的是,在Windows中没有这样的东西可以直接在命令行或批处理文件中使用,尽管现代版本的Windows肯定提供了隐藏在其中的ZIP功能。



严格来说,批处理不能做这样的事情,但问题可以间接解决。



这是其中一种解决方案(对不起,我没有测试过): http://superuser.com/questions/110 991 / can-you-zip-a-file-from-the-command-prompt-only-windows-built-in-capabili [ ^ ]。



基本上,这种方法在引擎盖下使用WSH: https: //en.wikipedia.org/wiki/Windows_Script_Host [ ^ ]。



WSH通过JavaScript或VBScript编程使用,不需要任何安装。那么,为什么不直接使用呢?其中一种方法是使用.WSF文件 - 请看下面的链接。



一般来说,我建议您查看使用批处理文件的整个方法,这几乎已经过时,难以调试,等等。如何直接使用WSH,使用完全可以批量使用的.WSF文件(也是过时的,但至少可以调试代码)。无论如何,你可以简单地点击这个文件来执行它,就像批处理文件一样,不需要安装任何东西: https ://en.wikipedia.org/wiki/Windows_Script_File [ ^ ]。



或者你可以使用PowerShell,但你需要安装它。或者其他一些应用。你需要存档吗?如果这不是你真正需要的,那该怎么办?也许您需要一个版本控制系统,或其他什么?试想一下。



-SA
Please see my comment to the question. You are missing the application or command with ZIP capabilities.

So, first approach is to have such application. I would recommend, first of all, open source 7-Zip:
https://en.wikipedia.org/wiki/7-Zip[^],
http://www.7-zip.org/[^].

Amazingly, there is no such thing in Windows which you could use directly in a command line or batch file, despite the fact that modern versions of Windows are certainly supplied with the ZIP capabilities hidden inside.

Strictly speaking, batch along is not capable of doing such thing, but the problem can be solved indirectly.

This is one of such solutions (sorry, I did not test it): http://superuser.com/questions/110991/can-you-zip-a-file-from-the-command-prompt-using-only-windows-built-in-capabili[^].

Essentially, this approach uses WSH under the hood: https://en.wikipedia.org/wiki/Windows_Script_Host[^].

WSH is used through JavaScript or VBScript programming and does not require any installations. So, why not using it directly? One of the ways to do so would be using .WSF file — please see a link below.

Generally, I would recommend to review your whole approach of using batch files, which are pretty much obsolete, hard to debug, and so on. How about using WSH directly, with .WSF file which you can use exactly as batch (also obsolete, but at least you can debug code). Anyway, you can simply click on this file to get it executed, as with a batch file, and don't need to install anything: https://en.wikipedia.org/wiki/Windows_Script_File[^].

Or you can use PowerShell, but you need to install it. Or some other application. Do you need archiving? What if this is not what you really need; maybe you need a Revision Control System instead, or something else? Just think about it.

—SA


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

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