Имя пользователя:
Пароль:  
Помощь | Регистрация | Забыли пароль?  

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

Аватара для El Sanchez

Ветеран


Contributor


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

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


ruslaw, пробуйте:
читать дальше »

Код: Выделить весь код
Option Explicit

Const ForReading = 1, ForWriting = 2
Dim objArgs, objFSO, objFolder, objFile, objTextStream, objResultTextStream
Dim objRegExp, objMatches, objMatch
Dim strFolder

'Check arguments count
Set objArgs = WScript.Arguments
If objArgs.Count = 0 Then
	WScript.Echo "Syntax: "	& WScript.ScriptName & " ""path to folder"""
	WScript.Quit(1)
End If

'Check first argument is folder
Set objFSO = CreateObject("Scripting.FileSystemObject")
strFolder = WScript.Arguments(0)
If Not objFSO.FolderExists(strFolder) Then
	WScript.Echo "Specified folder " & strFolder & " not exists"
	WScript.Quit(1)
End If

'Create regexp object
Set objRegExp = CreateObject("VBScript.RegExp")
objRegExp.Pattern = """http:\/\/[\w-]+\.livejournal.com\/\d+\.html\?thread\=\d+#t\d+"""
objRegExp.Global = True
objRegExp.IgnoreCase = True

'Create result log-file
Set objResultTextStream = objFSO.OpenTextFile(objFSO.GetParentFolderName(WScript.ScriptFullName) & "\result.log", ForWriting, True)

'Enumerate html-files in folder
Set objFolder = objFSO.GetFolder(strFolder)
For Each objFile in objFolder.Files
	If (UCase(objFSO.GetExtensionName(objFile.Name)) = "HTML") And (objFile.Size > 0) Then
		'Open file
		Set objTextStream = objFSO.OpenTextFile(objFile.Path, ForReading)
		'Read file and get matches
		Set objMatches = objRegExp.Execute(objTextStream.ReadAll)
		For Each objMatch In objMatches
			'Write match
			objResultTextStream.WriteLine objMatch.Value
		Next
	End If
Next

'Close result log-file
objResultTextStream.Close

'Cleanup
Set objArgs = Nothing
Set objFSO = Nothing
Set objFolder = Nothing
Set objFile = Nothing
Set objTextStream = Nothing
Set objResultTextStream = Nothing
Set objRegExp = Nothing
Set objMatches = Nothing
Set objMatch = Nothing
Set strFolder = Nothing

WScript.Echo "Done."
Это сообщение посчитали полезным следующие участники:

Отправлено: 13:59, 05-06-2014 | #3