Board logo

标题: 100有偿请求制作zip压缩包内文件批处理脚本 [打印本页]

作者: 33571918    时间: 2017-10-29 00:56     标题: 100有偿请求制作zip压缩包内文件批处理脚本

批量修改zip压缩包内txt文件字符替换脚本
作者: 见与不见    时间: 2017-10-29 10:05

这个要知道文件名,单独解压这个出来  然后重新压缩回去
作者: qazplm    时间: 2017-10-29 11:09

回复 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
复制代码

作者: 老刘1号    时间: 2017-10-29 16:10

本帖最后由 老刘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. For Each File In objFolder.Files
  25. If UCase(FSO.GetExtensionName(File)) = "TXT" Then
  26. Str = fso.OpenTextFile(File,1).ReadAll
  27. Str = Replace(Str,OldStr,NewStr)
  28. fso.OpenTextFile(File,2,True).Write Str
  29. End If
  30. Next
  31. For Each folder In objFolder.SubFolders
  32. ErgodicFolder folder
  33. Next
  34. End Sub
  35. Sub UnZip(myZipFile, myTargetDir)
  36.     Set fso = CreateObject("Scripting.FileSystemObject")
  37.     If Not fso.FileExists(myZipFile) Then
  38.         Exit Sub
  39.     ElseIf fso.GetExtensionName(myZipFile) <> "zip" Then
  40.         Exit Sub
  41.     ElseIf Not fso.FolderExists(myTargetDir) Then
  42.         fso.CreateFolder(myTargetDir)
  43.     End If
  44.     myZipFile=fso.GetFile(myZipFile).Path
  45.     myTargetDir=fso.GetFolder(myTargetDir).Path
  46.     Set objShell = CreateObject("Shell.Application")
  47.     Set objSource = objShell.NameSpace(myZipFile)
  48.     Set objFolderItem = objSource.Items()
  49.     Set objTarget = objShell.NameSpace(myTargetDir)
  50.     intOptions = 256
  51.     objTarget.CopyHere objFolderItem, intOptions
  52. End Sub
  53. Sub Zip(mySourceDir, myZipFile)
  54.     Set fso = CreateObject("Scripting.FileSystemObject")
  55.     If fso.GetExtensionName(myZipFile) <> "zip" Then
  56.         Exit Sub
  57.     ElseIf fso.FolderExists(mySourceDir) Then
  58.         FType = "Folder"
  59.     ElseIf fso.FileExists(mySourceDir) Then
  60.         FType = "File"
  61.         FileName = fso.GetFileName(mySourceDir)
  62.         FolderPath = fso.GetFile(mySourceDir).ParentFolder
  63.     Else
  64.         Exit Sub
  65.     End If
  66.     Set f = fso.CreateTextFile(myZipFile, True)
  67.     f.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
  68.     f.Close
  69.     myZipFile=fso.GetFile(myZipFile).Path
  70.     Set objShell = CreateObject("Shell.Application")
  71.     Select Case Ftype
  72.         Case "Folder"
  73.         Set objSource = objShell.NameSpace(mySourceDir)
  74.         Set objFolderItem = objSource.Items()
  75.         Case "File"
  76.         Set objSource = objShell.NameSpace(FolderPath)
  77.         Set objFolderItem = objSource.ParseName(FileName)
  78.     End Select
  79.     Set objTarget = objShell.NameSpace(myZipFile)
  80.     intOptions = 256
  81.     objTarget.CopyHere objFolderItem, intOptions
  82.     Do
  83.         WScript.Sleep 1000
  84.     Loop Until objTarget.Items.Count > 0
  85. End Sub
复制代码





欢迎光临 批处理之家 (http://www.bathome.net/) Powered by Discuz! 7.2