Имя пользователя:
Пароль:
 

Показать сообщение отдельно

Ветеран


Сообщения: 27449
Благодарности: 8088

Профиль | Отправить PM | Цитировать


Цитата ul9:
Не пробовала. »
Странно. Было очень похоже на то.

Ладно. Пробуйте так:
читать дальше »
Код: Выделить весь код
<html id="appSampleScriptRunner">
	<head>
		<meta charset="windows-1251">
		<meta http-equiv="Content-Type" content="text/html; charset=windows-1251">
		<meta http-equiv="Content-Language" content="ru">
		<title>Sample Script Runner</title>
		<hta:Application
			Id              = "appTextReplacer"
			Icon            = "%SystemRoot%\System32\wscript.exe"
			ApplicationName = "Sample Script Runner"
			Border          = "normal"
			BorderStyle     = "normal"
			Caption         = "yes"
			ContextMenu     = "no"
			InnerBorder     = "yes"
			MaximizeButton  = "yes"
			MinimizeButton  = "yes"
			Navigable       = "no"
			Scroll          = "auto"
			ScrollFlat      = "no"
			Selection       = "no"
			ShowInTaskbar   = "yes"
			SingleInstance  = "yes"
			SysMenu         = "yes"
			Version         = "1.1"
			WindowState     = "normal"
		/>
		
		<style type="text/css">
			body {
				font: x-small Verdana, Arial, sans-serif;
				color: WindowText;
				background-color: ButtonFace;
			}
		</style>
		
		<script language="VBScript">
			Option Explicit
			
			'==========================================================================
			Sub Window_OnLoad
				Dim strKey
				
				Dim objHTMLElement_Outer
				Dim objHTMLElement
				
				Dim lngColumns
				Dim lngColumn
				
				Dim elem
				
				If objFSO.FileExists(strIniFile) Then
					lngColumns = Int(Sqr(objDictionary.Count) + 1)
					lngColumn = 1
					
					For Each strKey In objDictionary.Keys
						If lngColumn = 1 Then
							Set objHTMLElement_Outer = document.createElement("div")
						End If
						
						Set objHTMLElement = document.createElement("div")
						
						With objHTMLElement
							.id    = strKey
							
							For Each elem In Array("FolderForScan", "FileExtension", "FileWhatFind", "FileReplaceBy")
								.title = .title & elem & ": " & vbTab & objDictionary.Item(strKey).Item(elem) & vbCrLf
							Next
							
							With .style
								.display     = "inline"
								
								.width       = window.screen.availWidth  \  8
								.height      = window.screen.availHeight \ 12
								
								.borderWidth = "thick"
								.borderStyle = "outset"
								
								.margin      = "0.5em"
								.padding     = "0.5em"
								
								.backgroundColor = strKey
							End With
							
							.onclick     = GetRef("OnClickButtonRunScript")
						End With
						
						objHTMLElement_Outer.appendChild objHTMLElement
						
						If lngColumn = lngColumns Then
							document.body.appendChild objHTMLElement_Outer
							
							lngColumn = 1
						Else
							lngColumn = lngColumn + 1
						End If
					Next
					
					document.body.appendChild objHTMLElement_Outer
					
					Set objHTMLElement = document.createElement("textarea")
					
					With objHTMLElement
						.id            = "ProcessLog"
						.rows          = "25"
						.cols          = "80"
						.readOnly      = "true"
						.style.display = "none"
					End With
					
					document.body.appendChild objHTMLElement
					
					With window
						.resizeTo document.body.scrollWidth + 25, document.body.scrollHeight + 32
						.moveTo (.screen.availWidth - document.body.offsetWidth) \ 2, (.screen.availHeight - document.body.offsetHeight) \ 2
					End With
				End If
			End Sub
			'==========================================================================
			
			'==========================================================================
			Sub OnClickButtonRunScript()
				document.getElementById("ProcessLog").value = _
					"Folder for scan: " & vbTab & objDictionary.Item(window.event.srcElement.id).Item("FolderForScan") & vbCrLf & _
					"File extension:  " & vbTab & objDictionary.Item(window.event.srcElement.id).Item("FileExtension") & vbCrLf & _
					"File what find:  " & vbTab & objDictionary.Item(window.event.srcElement.id).Item("FileWhatFind") & vbCrLf & _
					"File replace by: " & vbTab & objDictionary.Item(window.event.srcElement.id).Item("FileReplaceBy") & vbCrLf & vbCrLf
				
				With objFSO.OpenTextFile(objDictionary.Item(window.event.srcElement.id).Item("FileWhatFind"), ForReading)
					strWhatFind = .ReadAll()
					.Close
				End With
				
				If objFSO.GetFile(objDictionary.Item(window.event.srcElement.id).Item("FileReplaceBy")).Size > 0 Then
					With objFSO.OpenTextFile(objDictionary.Item(window.event.srcElement.id).Item("FileReplaceBy"), ForReading)
						strReplaceBy = .ReadAll()
						.Close
					End With
				Else
					strReplaceBy = ""
				End If
				
				document.getElementById("ProcessLog").style.display = "block"
				
				With window
					.resizeTo document.body.scrollWidth + 25, document.body.scrollHeight + 32
					.moveTo (.screen.availWidth - document.body.offsetWidth) \ 2, (.screen.availHeight - document.body.offsetHeight) \ 2
				End With
				
				ScanSubFolders objFSO.GetFolder(objDictionary.Item(window.event.srcElement.id).Item("FolderForScan"))
			End Sub
			'==========================================================================
			
			'==========================================================================
			Sub ScanSubFolders(objFolder)
				Dim objSubFolder
				Dim objFile
				
				Dim strContent
				
				document.getElementById("ProcessLog").value = document.getElementById("ProcessLog").value & "[" & objFolder.Path & "]" & vbCrLf
				
				For Each objFile In objFolder.Files
					If UCase(objFSO.GetExtensionName(objFile.Name)) = UCase(objDictionary.Item(window.event.srcElement.id).Item("FileExtension")) Then
						document.getElementById("ProcessLog").value = document.getElementById("ProcessLog").value & "  " & objFile.Name & vbCrLf
						
						If objFile.Size > 0 Then
							With objFSO.OpenTextFile(objFile.Path, ForReading)
								strContent = .ReadAll()
								.Close
							End With
							
							If InStr(1, strContent, strWhatFind, vbTextCompare) > 0 Then
								document.getElementById("ProcessLog").value = document.getElementById("ProcessLog").value & "    Fragment for replace found" & vbCrLf
								
								With objFSO.OpenTextFile(objFile.Path, ForWriting)
									.Write Replace(strContent, strWhatFind, strReplaceBy)
									.Close
								End With
							End If
						End If
					End If
				Next
				
				For Each objSubFolder In objFolder.SubFolders
					ScanSubFolders objSubFolder
				Next
			End Sub
			'=============================================================================
			
			Const ForReading   = 1
			Const ForWriting   = 2
			
			
			Dim objDictionary
			Dim objFSO
			
			Dim strIniFile
			
			Dim strLine
			Dim strKey
			
			Dim strWhatFind
			Dim strReplaceBy
			
			
			Set objDictionary = CreateObject("Scripting.Dictionary")
			Set objFSO        = CreateObject("Scripting.Filesystemobject")
			
			With objFSO
				strIniFile = .BuildPath(.GetParentFolderName(Replace(appTextReplacer.commandLine, """", "")), .GetBaseName(appTextReplacer.commandLine) & ".ini")
				
				If .FileExists(strIniFile) Then
					With .OpenTextFile(strIniFile, ForReading)
						Do Until .AtEndOfStream
							strLine = Trim(.ReadLine())
							
							If Len(strLine) > 0 Then
								If Left(strLine, 1) = "[" And Right(strLine, 1) = "]" Then
									strKey = Mid(strLine, 2, Len(strLine) - 2)
									objDictionary.Add strKey, CreateObject("Scripting.Dictionary")
								Else
									objDictionary.Item(strKey).Add Trim(Split(strLine, "=")(0)), Trim(Split(strLine, "=")(1))
								End If
							End If
						Loop
						
						.Close
					End With
				Else
					MsgBox "Ini file [" & strIniFile & "] not found"
					
					window.close
				End If
			End With
		</script>
	</head>
	
	<body scroll="auto">
	</body>
</html>

Скрипт больше не нужен. Но понадобится ini-файл настроек, одноимённый hta-файлу. Выглядеть он может примерно так:
читать дальше »
Код: Выделить весь код
[Red]
FolderForScan=E:\Песочница\0191\0001
FileExtension=htm
FileWhatFind=E:\Песочница\0191\Найти это2.txt
FileReplaceBy=E:\Песочница\0191\заменить этим2.txt

[Green]
FolderForScan=E:\Песочница\0002
FileExtension=htm
FileWhatFind=E:\Песочница\02\Найти это.txt
FileReplaceBy=E:\Песочница\02\заменить этим.txt

[Blue]
FolderForScan=E:\Песочница\0003
FileExtension=htm
FileWhatFind=E:\Песочница\03\Найти это.txt
FileReplaceBy=E:\Песочница\03\заменить этим.txt

[SpringGreen]
FolderForScan=E:\Песочница\0003
FileExtension=htm
FileWhatFind=E:\Песочница\03\Найти это.txt
FileReplaceBy=E:\Песочница\03\заменить этим.txt

[DarkSlateBlue]
FolderForScan=E:\Песочница\0003
FileExtension=htm
FileWhatFind=E:\Песочница\03\Найти это.txt
FileReplaceBy=E:\Песочница\03\заменить этим.txt

[#CFCFF0]
FolderForScan=E:\Песочница\0003
FileExtension=htm
FileWhatFind=E:\Песочница\03\Найти это.txt
FileReplaceBy=E:\Песочница\03\заменить этим.txt

[GreenYellow]
FolderForScan=E:\Песочница\0003
FileExtension=htm
FileWhatFind=E:\Песочница\03\Найти это.txt
FileReplaceBy=E:\Песочница\03\заменить этим.txt


Скорее всего, ошибок будет куча.
Это сообщение посчитали полезным следующие участники:

Отправлено: 05:26, 27-10-2012 | #33