简体   繁体   English

批处理文件以从Zip文件夹中提取特定文件并重命名以包含Zip名称

[英]Batch file to Extract a specific file from Zip folder and rename to include Zip name

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. 我有大约300个zip文件,这些文件都包含一个名为SP_OUT.db的文件,其中包含一个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. 我想解压缩文件SP_OUT.db并将其放置在新文件夹中。 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. 但是,由于所有文件都具有相同的名称,因此我想重命名它们以包含其来源的ZIP的名称。

For example 例如

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 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

Any help with this would be great. 任何帮助都会很棒。

Thanks 谢谢

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. 如果您不介意安装程序7zip,则似乎应该有一种方法可以做到这一点。 You could then incorporate a 7zip command like the one below to only extract the SP_OUT.db files. 然后,您可以合并以下7zip命令,仅提取SP_OUT.db文件。

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

extracts all SP_OUT.db files from archive archive.zip to c:\\soft folder 将所有SP_OUT.db文件从存档archive.zip提取到c:\\ soft文件夹

May need to try using the x argument instead of e 可能需要尝试使用x参数代替e

Source: http://sevenzip.sourceforge.jp/chm/cmdline/commands/extract.htm 来源: http//sevenzip.sourceforge.jp/chm/cmdline/commands/extract.htm

.

EDIT: 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. 但是我还没有解决如何将原始zip名称添加到提取的SP_OUT.db文件名的开头。

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. 我在下面的脚本中标记了您需要执行此操作的位置,并在其后添加了“ REN”(重命名)以更改提取文件的名称。

@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

just read the man page: 只需阅读手册页:

7-Zip [64] 9.20  Copyright (c) 1999-2010 Igor Pavlov  2010-11-18

Usage: 7z  [...]  [...]
       []


  a: Add files to archive
  b: Benchmark
  d: Delete files from archive
  e: Extract files from archive (without using directory names)
  l: List contents of archive
  t: Test integrity of archive
  u: Update files to archive
  x: eXtract files with full paths

  -ai[r[-|0]]{@listfile|!wildcard}: Include archives
  -ax[r[-|0]]{@listfile|!wildcard}: eXclude archives
  -bd: Disable percentage indicator
  -i[r[-|0]]{@listfile|!wildcard}: Include filenames
  -m{Parameters}: set compression Method
  -o{Directory}: set Output directory
  -p{Password}: set Password
  -r[-|0]: Recurse subdirectories
  -scs{UTF-8 | WIN | DOS}: set charset for list files
  -sfx[{name}]: Create SFX archive
  -si[{name}]: read data from stdin
  -slt: show technical information for l (List) command
  -so: write data to stdout
  -ssc[-]: set sensitive case mode
  -ssw: compress shared files
  -t{Type}: Set type of archive
  -u[-][p#][q#][r#][x#][y#][z#][!newArchiveName]: Update options
  -v{Size}[b|k|m|g]: Create volumes
  -w[{path}]: assign Work directory. Empty path means a temporary directory
  -x[r[-|0]]]{@listfile|!wildcard}: eXclude filenames
  -y: assume Yes on all queries

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从批处理文件中提取 7-zip 文件到它们的包含目录中? - Extract 7-zip files into their containing directory from a batch file? 如何从文本文件压缩子文件夹列表,并在文件名中包含父文件夹名称? - How to zip list of subfolders from text file and include parent folder name in filename? 使用批处理文件静默提取 zip 文件 - extract zip files silently using batch file 如何使用批处理文件重命名或创建带有其内容名称的 zip 文件 - How to rename or create a zip file with the name of its content using a batch file 从批处理文件的路径中提取文件夹名称 - Extract folder name from path in batch file 从多个 7-zip 文件中提取特定的文件扩展名 - Extract specific file extensions from multiple 7-zip files Windows Batch:将文件夹重命名为其中的文件名 - Windows Batch: Rename a folder to the name of a file inside 如何在Windows批处理文件中编写命令以将zip文件从FTP路径复制到计算机中的本地文件夹 - How to write command in windows batch file to copy a zip file from an FTP path to a local folder in my computer 如何用WinRAR创建ZIP文件,且ZIP文件的名称为当前文件夹的名称? - How to create a ZIP file with WinRAR with name of ZIP file being name of current folder? 使用7zip提取存档文件,文件夹中有空格 - Extract archive file using 7zip with space(s) in the folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM