2013-11-28 92 views
2

我有大約300個zip文件,它們都會有一個名爲SP_OUT.db的文件,其中包含壓縮文件夾中的一個文件夾。這些文件夾本身可能會或可能不會被壓縮。 我想解壓文件SP_OUT.db並放置在一個新文件夾中。但是,由於所有文件都是相同的名稱,我想將其重命名爲包含其來源的ZIP的名稱。批處理文件從Zip文件夾中提取特定文件並重命名爲包含郵編名稱

例如

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

任何幫助,這將是巨大的。

感謝

+0

您使用哪個程序從zip文件中提取?壓縮? 7zip的? WinRAR的? – foxidrive

回答

-2

剛讀手冊頁:

 

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 

+0

我正在使用7zip – user2446846

3

什麼操作系統您使用的? 看起來應該有辦法做到這一點,如果你不介意安裝程序7zip。 然後,您可以合併下面的7zip命令來僅提取SP_OUT.db文件。

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

提取物存檔archive.zip所有SP_OUT.db文件到c:\文件夾中軟

可能需要使用x參數,而不是e

來源嘗試:http://sevenzip.sourceforge.jp/chm/cmdline/commands/extract.htm

編輯:找出了一個腳本來提取每個文件。 但是,我還沒有制定出如何將原始zip名稱添加到解壓縮SP_OUT.db文件名的開頭。

我已經在下面的腳本中標記了你需要做這件事的地方,並且在它之後添加'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 
+0

@ user2446846請記住選擇此答案是否有幫助 – Durry42

相關問題