标题: 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 - @echo off
- rem 测试前先备份zip原文件
- rem 指定WinRAR的安装路径
- set "rarpath=C:\Program Files\WinRAR\WinRAR.exe"
- for /f "delims=" %%a in ('dir /a-d/b *.zip') do (
- echo;"%%a"
- "%rarpath%" x -r -y -ibck "%%a" *.txt "%~dp0\$tmp\"
- pushd "%~dp0\$tmp\"
- for /r %%b in (*.txt) do (
- setlocal enabledelayedexpansion
- (for /f "tokens=1* delims=:" %%i in ('findstr /n .* "%%b"') do (
- set "line=%%j"
- echo;!line:需替换的字符串=替换后的字符串!
- ))>"%%~dpb$t.tmp"
- move /y "%%~dpb$t.tmp" "%%~dpnxb"
- endlocal
- )
- "%rarpath%" u -r -ibck "%~dp0ini.zip" *.txt
- popd
- rd /q /s "%~dp0\$tmp\"
- )
- pause
复制代码
作者: 老刘1号 时间: 2017-10-29 16:10
本帖最后由 老刘1号 于 2017-10-29 19:15 编辑
回复 1# 33571918
无需任何第三方,存批即可
如果觉得可用,请支付到论坛支付宝账号
- OldStr="原来的字符串"
- NewStr="新的字符串"
-
- ' & @Echo off & Cls 2>Nul 3>nul
- ' & For /r "你的ZIP文件所在的路径" %%a in (*.ZIP) Do Echo "%%~fa" && Cscript -Nologo -E:Vbscript "%~0" "%%~fa"
- ' & Pause & Goto :EOF
- Rem Code BY 老刘
- Rem Zip,UnZip函数块感谢Demon、乱码
- Rem 其他均为原创
- Randomize
- YourZipFilePath=Wscript.Arguments(0)
- Dim fso
- Set fso = CreateObject("Scripting.FileSystemObject")
- TmpFolderName = Replace(Rnd,".","")
- fso.GetFolder(fso.GetSpecialFolder(2)&"\").SubFolders.Add TmpFolderName
- TmpFolderPath = fso.GetSpecialFolder(2)&"\"&TmpFolderName
- UnZip YourZipFilePath, TmpFolderPath
- ErgodicFolder TmpFolderPath,OldStr,NewStr
- Zip TmpFolderPath,YourZipFilePath
-
-
-
- Sub ErgodicFolder(Inputfolder,OldStr,NewStr)
- Dim objFolder,File,folder
- Dim fso
- Set fso = CreateObject("Scripting.FileSystemObject")
- Set objFolder=FSO.getFolder(Inputfolder)
-
- For Each File In objFolder.Files
- If UCase(FSO.GetExtensionName(File)) = "TXT" Then
- Str = fso.OpenTextFile(File,1).ReadAll
- Str = Replace(Str,OldStr,NewStr)
- fso.OpenTextFile(File,2,True).Write Str
- End If
- Next
-
- For Each folder In objFolder.SubFolders
- ErgodicFolder folder
- Next
-
- End Sub
-
- Sub UnZip(myZipFile, myTargetDir)
- Set fso = CreateObject("Scripting.FileSystemObject")
- If Not fso.FileExists(myZipFile) Then
- Exit Sub
- ElseIf fso.GetExtensionName(myZipFile) <> "zip" Then
- Exit Sub
- ElseIf Not fso.FolderExists(myTargetDir) Then
- fso.CreateFolder(myTargetDir)
- End If
- myZipFile=fso.GetFile(myZipFile).Path
- myTargetDir=fso.GetFolder(myTargetDir).Path
- Set objShell = CreateObject("Shell.Application")
- Set objSource = objShell.NameSpace(myZipFile)
- Set objFolderItem = objSource.Items()
- Set objTarget = objShell.NameSpace(myTargetDir)
- intOptions = 256
- objTarget.CopyHere objFolderItem, intOptions
- End Sub
-
- Sub Zip(mySourceDir, myZipFile)
- Set fso = CreateObject("Scripting.FileSystemObject")
- If fso.GetExtensionName(myZipFile) <> "zip" Then
- Exit Sub
- ElseIf fso.FolderExists(mySourceDir) Then
- FType = "Folder"
- ElseIf fso.FileExists(mySourceDir) Then
- FType = "File"
- FileName = fso.GetFileName(mySourceDir)
- FolderPath = fso.GetFile(mySourceDir).ParentFolder
- Else
- Exit Sub
- End If
- Set f = fso.CreateTextFile(myZipFile, True)
- f.Write "PK" & Chr(5) & Chr(6) & String(18, Chr(0))
- f.Close
- myZipFile=fso.GetFile(myZipFile).Path
- Set objShell = CreateObject("Shell.Application")
- Select Case Ftype
- Case "Folder"
- Set objSource = objShell.NameSpace(mySourceDir)
- Set objFolderItem = objSource.Items()
- Case "File"
- Set objSource = objShell.NameSpace(FolderPath)
- Set objFolderItem = objSource.ParseName(FileName)
- End Select
- Set objTarget = objShell.NameSpace(myZipFile)
- intOptions = 256
- objTarget.CopyHere objFolderItem, intOptions
- Do
- WScript.Sleep 1000
- Loop Until objTarget.Items.Count > 0
- End Sub
复制代码
欢迎光临 批处理之家 (http://www.bathome.net/) |
Powered by Discuz! 7.2 |