将ZIP文件的内容批量重命名为ZIP文件名 [英] Batch Rename contents of ZIP file to ZIP file name

查看:620
本文介绍了将ZIP文件的内容批量重命名为ZIP文件名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题非常类似于:

在Batch中基于zip文件重命名提取的文件

我有470个.zip文件,每个文件都包含两个文件(.mp3和.cdg)-它们是卡拉OK文件.

ZIP文件明确命名为(Abba-Money Money Money.zip),但是该ZIP文件的内容需要重命名(例如FIK001ABBA_02 _- ABBA -_ MONEY_MONEY_MONEY.mp3)./p>

因此,我希望该批处理文件执行以下操作:

  • 提取文件
  • 将zip文件的内容重命名为zip文件名.
  • 例如:
  • FIK001ABBA_02 _- ABBA -_ MONEY_MONEY_MONEY.mp3
  • FIK001ABBA_02 _- ABBA -_ MONEY_MONEY_MONEY.cdg
  • 重命名为
  • Abba-Money Money Money.mp3
  • Abba-Money Money Money.cdg
  • 然后将文件重新添加到zip文件中

我看过上面类似的文章,但是,它讨论的是将* .7z解压缩为我的文件* .Zip.请说明:-)

这是代码:

md textfiles
for %%f in (*.zip) do (
winzip -v "%%f"
move *.txt textfiles\%%~nf.txt
)
xcopy textfiles\*.txt originalfolder
rd textfiles /s /q

解决方案

@ECHO OFF
SETLOCAL 
(SET workdir=.\textfiles)
IF EXIST "%workdir%\." ECHO Choose a directory name that doesn't exist&GOTO :EOF 
FOR %%f IN (*.zip) DO CALL :process %%f
GOTO :eof

::
::  
::
:process
MD "%workdir%"
wzunzip %1 "%workdir%" >nul
PUSHD "%workdir%"
FOR /f "tokens=1*delims=-" %%i IN ('dir /b /a-d') DO CALL :procren %%i %%j
POPD
:: Not sure whether you want to ADD (as you say) 
:: or REPLACE (seems more logical)
:: 
DEL %1
wzzip -m %1 "%workdir%\*.*" >nul
IF EXIST "%workdir%\." RD "%workdir%" /S /Q
GOTO :eof

:procren %%i %%j
SET filename=%1-%2
SET newname=%2
SET newname=%newname:_= %
SET newname=%newname:-= -%
REN %filename% "%newname%"
GOTO :eof

请注意以下几点:

  • 我不确定您是否要添加或替换.ZIP文件的内容.该代码将替换.如果您确实要添加,请删除DEL %1行.
  • WINZIP7ZIP不同,但相似的产品
  • 我使用的是相对较旧的WINZIP版本,该版本具有一对针对批处理使用的命令行实用程序(WZZIPWZUNZIP)
  • 我的WZZIP版本(v3.2,内部版本8668)似乎存在一个错误,如果将"dirname\*.*移动到zip中,则-m(移动)选项将在delete目录中.我将继续进行介绍-但这就是为什么将工作目录的RD与MD一起选通并放置在:process例程中,而不是在主例程中的原因.

My question is very similar to:

Rename extracted file based on zip file in Batch

I have 470 .zip files which each contain two files (.mp3 & .cdg) - they are karaoke files.

The ZIP files are cleanly named (Abba - Money Money Money.zip), however the contents, of the ZIP file need to be renamed (e.g FIK001ABBA_02_-ABBA-_MONEY_MONEY_MONEY.mp3).

So, I would like the batch file to do the following:

  • Extract the files
  • Rename the contents, of the zip file to the zip file name.
  • e.g:
  • FIK001ABBA_02_-ABBA-_MONEY_MONEY_MONEY.mp3
  • FIK001ABBA_02_-ABBA-_MONEY_MONEY_MONEY.cdg
  • renamed to
  • Abba - Money Money Money.mp3
  • Abba - Money Money Money.cdg
  • The files are then added back into the zip file

I've looked over the similar posting above, however, it talks about unzipping *.7z my files are *.Zip. Please explain :-)

Here is the code:

md textfiles
for %%f in (*.zip) do (
winzip -v "%%f"
move *.txt textfiles\%%~nf.txt
)
xcopy textfiles\*.txt originalfolder
rd textfiles /s /q

解决方案

@ECHO OFF
SETLOCAL 
(SET workdir=.\textfiles)
IF EXIST "%workdir%\." ECHO Choose a directory name that doesn't exist&GOTO :EOF 
FOR %%f IN (*.zip) DO CALL :process %%f
GOTO :eof

::
::  
::
:process
MD "%workdir%"
wzunzip %1 "%workdir%" >nul
PUSHD "%workdir%"
FOR /f "tokens=1*delims=-" %%i IN ('dir /b /a-d') DO CALL :procren %%i %%j
POPD
:: Not sure whether you want to ADD (as you say) 
:: or REPLACE (seems more logical)
:: 
DEL %1
wzzip -m %1 "%workdir%\*.*" >nul
IF EXIST "%workdir%\." RD "%workdir%" /S /Q
GOTO :eof

:procren %%i %%j
SET filename=%1-%2
SET newname=%2
SET newname=%newname:_= %
SET newname=%newname:-= -%
REN %filename% "%newname%"
GOTO :eof

Just a few notes:

  • I'm not sure whether you want to ADD or REPLACE the content of your .ZIP files. The code will REPLACE. If you truly want to ADD then remove the DEL %1 line.
  • WINZIP and 7ZIP are different, but similar products
  • I use a relatively old version of WINZIP, which has a pair of command-line utilities available (WZZIP and WZUNZIP) aimed at batch use
  • There appears to be a bug with my WZZIP version (v3.2, build 8668) where the -m (move) option will delete the directory if "dirname\*.* is MOVED into the zip. I'll chase this up - but that's why the RD of the work directory is gated and placed with the MD within the :process routine, not in the main routine.

这篇关于将ZIP文件的内容批量重命名为ZIP文件名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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