批处理文件提取邮编文件夹中的特定文件,并改名为包括邮编名 [英] Batch file to Extract a specific file from Zip folder and rename to include Zip name

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

问题描述

我有大约300号文件都将有一个名为SP_OUT.db包含withing中的zip文件夹中的一个文件。这些文件夹本身可以或可以不被压缩。
我想解压缩到一个新的文件夹中SP_OUT.db和地点。然而,由于所有的文件都是一样的名字我想重新命名他们包括在它来自的ZIP的名称。

I have Approx 300 zip files that will all have a file called SP_OUT.db contained withing one of the folders in the zip. These folders themselves may or may not be be zipped. I want to unzipped the file SP_OUT.db and place in a new folder. However as all the files are the same name i want to rename them to include the name of the ZIP in which it came from.

例如

A11_21156_AHDW1_1.zip提取SP_OUT.db,并改名为A11_21156_AHDW1_1SP_OUT.db
A06_21047_APERCLASH1_1.zip提取SP_OUT.db并将其重命名为A06_21047_APERCLASH1_1.db

A11_21156_AHDW1_1.zip extract SP_OUT.db and rename it to A11_21156_AHDW1_1SP_OUT.db A06_21047_APERCLASH1_1.zip extract SP_OUT.db and rename it to A06_21047_APERCLASH1_1.db

任何帮助,这将是巨大的。

Any help with this would be great.

感谢

推荐答案

您使用的是什么操作系统?
看起来应该有办法做到这一点,如果你不介意安装该程序7zip的。
然后,您可以纳入一个7zip的命令,如下面只提取SP_OUT.db文件之一。

What OS are you using? It looks like there should be a way to do this if you don’t mind installing the program 7zip. You could then incorporate a 7zip command like the one below to only extract the SP_OUT.db files.

7z e archive.zip -oc:\soft SP_OUT.db -r

从提取档案archive.zip所有SP_OUT.db文件到c:\\文件夹中软

extracts all SP_OUT.db files from archive archive.zip to c:\soft folder

可能需要使用来看看X 参数,而不是电子

May need to try using the x argument instead of e

来源: http://sevenzip.sourceforge.jp/chm/cmdline/命令/ extract.htm

编辑:摸索出脚本提取每个文件。
但是我还没有制定出如何尚未到原来的ZIP名称添加到提取SP_OUT.db文件名的开始。

Worked out a script to extract each file. However I havent worked out yet how to add the original zip name to the start of the extracted SP_OUT.db filename.

我标志着下面,你woudl需要做到这一点的脚本的地方,增加了REN(重命名)后,改变提取的文件的名称。

I've marked the place in the script below where you woudl need to do this, and added 'REN' (Rename) after it to change the name of the extracted file.

@ECHO off
TITLE All your SP_OUT.db are belong to us
SETLOCAL ENABLEDELAYEDEXPANSION

REM Set your working directories below.
set targetFile=SP_OUT.db
set sourceDir=%CD%\source
set outputDir=%CD%\output
set 7ziplocation=C:\Progra~1\7zip\7z.exe

:start
FOR /f "delims=" %%a IN ('dir/s/b/a-d "%sourcedir%\*.zip"') DO (
 %7ziplocation% e %%a -o%outputDir% SP_OUT.db -r
 CALL :process2 %%a
  )
GOTO :eof

:process2
SET "fdir=%1"
REM ********* %fdir% will be the full path including filename of original zip file.
REM ********* Work out how to get just zip file name and put save to variable here.
REN %outputDir%\SP_OUT.db %put_the_above_zip_name_here%_SP_OUT.db
GOTO :eof

这篇关于批处理文件提取邮编文件夹中的特定文件,并改名为包括邮编名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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