找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19373|回复: 3

100有偿请求制作zip压缩包内文件批处理脚本

  [复制链接]
发表于 2017-10-29 00:56:13 | 显示全部楼层 |阅读模式
批量修改zip压缩包内txt文件字符替换脚本
发表于 2017-10-29 10:05:52 | 显示全部楼层
这个要知道文件名,单独解压这个出来  然后重新压缩回去
发表于 2017-10-29 11:09:01 | 显示全部楼层
回复 1# 33571918
  1. @echo off
  2. rem 测试前先备份zip原文件
  3. rem 指定WinRAR的安装路径
  4. set "rarpath=C:\Program Files\WinRAR\WinRAR.exe"
  5. for /f "delims=" %%a in ('dir /a-d/b *.zip') do (
  6.     echo;"%%a"
  7.     "%rarpath%" x -r -y -ibck "%%a" *.txt "%~dp0\$tmp"
  8.     pushd "%~dp0\$tmp"
  9.     for /r %%b in (*.txt) do (
  10.         setlocal enabledelayedexpansion
  11.         (for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%%b"') do (
  12.             set "line=%%j"
  13.             echo;!line:需替换的字符串=替换后的字符串!
  14.         ))>"%%~dpb$t.tmp"
  15.         move /y "%%~dpb$t.tmp" "%%~dpnxb"
  16.         endlocal
  17.     )
  18.     "%rarpath%" u -r -ibck "%~dp0ini.zip" *.txt
  19.     popd
  20.     rd /q /s "%~dp0\$tmp"
  21. )
  22. pause
复制代码
发表于 2017-10-29 16:10:17 | 显示全部楼层
本帖最后由 老刘1号 于 2017-10-29 19:15 编辑

回复 1# 33571918

无需任何第三方,存批即可
如果觉得可用,请支付到论坛支付宝账号
  1. OldStr="原来的字符串"
  2. NewStr="新的字符串"

  3. ' & @Echo off & Cls 2>Nul 3>nul
  4. ' & For /r "你的ZIP文件所在的路径" %%a in (*.ZIP) Do Echo "%%~fa" && Cscript -Nologo -E:Vbscript "%~0" "%%~fa"
  5. ' & Pause & Goto :EOF
  6. Rem Code BY 老刘
  7. Rem Zip,UnZip函数块感谢Demon、乱码
  8. Rem 其他均为原创
  9. Randomize
  10. YourZipFilePath=Wscript.Arguments(0)
  11. Dim fso
  12. Set fso = CreateObject("Scripting.FileSystemObject")
  13. TmpFolderName = Replace(Rnd,".","")
  14. fso.GetFolder(fso.GetSpecialFolder(2)&"").SubFolders.Add TmpFolderName
  15. TmpFolderPath = fso.GetSpecialFolder(2)&""&TmpFolderName
  16. UnZip YourZipFilePath, TmpFolderPath
  17. ErgodicFolder TmpFolderPath,OldStr,NewStr
  18. Zip TmpFolderPath,YourZipFilePath



  19. Sub ErgodicFolder(Inputfolder,OldStr,NewStr)
  20.         Dim objFolder,File,folder
  21.         Dim fso
  22.         Set fso = CreateObject("Scripting.FileSystemObject")
  23.         Set objFolder=FSO.getFolder(Inputfolder)
  24.        
  25.         For Each File In objFolder.Files
  26.                 If UCase(FSO.GetExtensionName(File)) = "TXT" Then
  27.                         Str = fso.OpenTextFile(File,1).ReadAll
  28.                         Str = Replace(Str,OldStr,NewStr)
  29.                         fso.OpenTextFile(File,2,True).Write Str
  30.                 End If
  31.         Next
  32.        
  33.         For Each folder In objFolder.SubFolders
  34.                 ErgodicFolder folder
  35.         Next
  36.        
  37. End Sub

  38. Sub UnZip(myZipFile, myTargetDir)
  39.     Set fso = CreateObject("Scripting.FileSystemObject")
  40.     If Not fso.FileExists(myZipFile) Then
  41.         Exit Sub
  42.     ElseIf fso.GetExtensionName(myZipFile) <> "zip" Then
  43.         Exit Sub
  44.     ElseIf Not fso.FolderExists(myTargetDir) Then
  45.         fso.CreateFolder(myTargetDir)
  46.     End If
  47.     myZipFile=fso.GetFile(myZipFile).Path
  48.     myTargetDir=fso.GetFolder(myTargetDir).Path
  49.     Set objShell = CreateObject("Shell.Application")
  50.     Set objSource = objShell.NameSpace(myZipFile)
  51.     Set objFolderItem = objSource.Items()
  52.     Set objTarget = objShell.NameSpace(myTargetDir)
  53.     intOptions = 256
  54.     objTarget.CopyHere objFolderItem, intOptions
  55. End Sub

  56. Sub Zip(mySourceDir, myZipFile)
  57.     Set fso = CreateObject("Scripting.FileSystemObject")
  58.     If fso.GetExtensionName(myZipFile) <> "zip" Then
  59.         Exit Sub
  60.     ElseIf fso.FolderExists(mySourceDir) Then
  61.         FType = "Folder"
  62.     ElseIf fso.FileExists(mySourceDir) Then
  63.         FType = "File"
  64.         FileName = fso.GetFileName(mySourceDir)
  65.         FolderPath = fso.GetFile(mySourceDir).ParentFolder
  66.     Else
  67.         Exit Sub
  68.     End If
  69.     Set f = fso.CreateTextFile(myZipFile, True)
  70.     f.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
  71.     f.Close
  72.     myZipFile=fso.GetFile(myZipFile).Path
  73.     Set objShell = CreateObject("Shell.Application")
  74.     Select Case Ftype
  75.         Case "Folder"
  76.         Set objSource = objShell.NameSpace(mySourceDir)
  77.         Set objFolderItem = objSource.Items()
  78.         Case "File"
  79.         Set objSource = objShell.NameSpace(FolderPath)
  80.         Set objFolderItem = objSource.ParseName(FileName)
  81.     End Select
  82.     Set objTarget = objShell.NameSpace(myZipFile)
  83.     intOptions = 256
  84.     objTarget.CopyHere objFolderItem, intOptions
  85.     Do
  86.         WScript.Sleep 1000
  87.     Loop Until objTarget.Items.Count > 0
  88. End Sub

复制代码

评分

参与人数 1技术 +1 收起 理由
happy886rr + 1 好样的

查看全部评分

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 01:37 , Processed in 0.016217 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表