创建一个批处理文件,该文件将压缩两个具有相同名称(但扩展名不同)的文件 [英] Create a batch file that will zip two files with the same name (but different extensions)

查看:191
本文介绍了创建一个批处理文件,该文件将压缩两个具有相同名称(但扩展名不同)的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对编程非常陌生,最近我开始在数据存档设施工作.我的大部分工作是将pdf和AutoCAD文件(.dwg)压缩在一起.我的经理让我手动执行此操作,并且有成千上万个要压缩的文件,所以我正在寻找一种更有效的方法.

I'm very new to programming and I recently started working at a data archive facility. A large part of my job is zipping pdf and AutoCAD files (.dwg) together. My manager has me doing this by hand and there are thousands of files to zip, so I am looking for a more efficient way.

目前,我有一个文件夹,其中包含约500个文件,其中250个是PDF,其中250个是工程图.每个pdf都有一个具有相同名称的匹配图纸,我想将它们成对地压缩在一起. (该zip文件应具有相同的名称.)

At the moment, I have a folder that contains about 500 files, 250 of them are PDFs and 250 of them are drawings. Each pdf has a matching drawing with the same name and I want to zip them together in pairs. (The zip file should have the same name.)

命名约定如下: 1.pdf 1.dwg 2.pdf 2.dwg ...等.

The naming convention is like this: 1.pdf 1.dwg 2.pdf 2.dwg ...etc.

我想创建类似这样的东西: 1.zip(包含1.pdf和1.dwg) 2.zip(包含2.pdf和2.dwg)

I want to create something like this: 1.zip (containing 1.pdf and 1.dwg) 2.zip (containing 2.pdf and 2.dwg)

我已经做过一些研究,并且我了解许多人已经使用批处理文件编写了类似的程序.但是,我发现自己陷入困境.我没有下载7zip或Windows 7附带的任何内容的权限.

I have done some research already and I understand that many people have written similar programs using batch files. However, I find myself stuck. I do not have permission to download 7zip or anything that doesn't come with Windows 7.

我尝试过这样的事情:

 @ECHO OFF
PATH=K:\FOD-FDC\TSG\HOLDING\ROTATE\OSU-090344\Vol_4_complete
FOR %F IN (*.dwg) DO 7Z a "%~nF.zip" "%~nF.dwg" "%~nF.pdf"

很明显,由于多种原因(最值得注意的是我没有7拉链),这是不对的,但我仍在尝试寻找解决方案.

Obviously it's not right for a lot of reasons (most notably I don't have 7-zip) but I am still trying to find a solution.

有人可以帮我吗?提前非常感谢您!

Can anyone help me out? Thank you so much in advance!

推荐答案

您必须将.Bat文件中的%翻倍:

You have to double the % in a .Batfile :

尝试这样

@ECHO OFF
set $PATH="K:\FOD-FDC\TSG\HOLDING\ROTATE\OSU-090344\Vol_4_complete\"
pushd %$path%
FOR %%F IN (*.dwg) DO 7Z a "%%~nF.zip" "%%~nF.dwg" "%%~nF.pdf"
popd
Echo Done !!!

这篇关于创建一个批处理文件,该文件将压缩两个具有相同名称(但扩展名不同)的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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