Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Программы » SciTE - Open Source Text Editor for Windows & Linux

Модерирует : gyra, Maz

Widok (23-11-2010 11:23): Лимит страниц. Продолжаем здесь  Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

   

idlenlazy

Junior Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору

Код:
' On Error Resume Next  
b]Option Explicit  
Dim [/b]
fso, WshShell, SciTE, selected, text, fc, f, Args  
Dim patrns, first_pattern, second_pattern, find_string, replace_string  
Set fso = WScript.CreateObject("Scripting.FileSystemObject")  
Set
WshShell = WScript.CreateObject("WScript.Shell")  
WshShell.CurrentDirectory = fso.GetParentFolderName (WScript.ScriptFullName)  
 
Set
SciTE = CreateObject("SciTE.Helper")  
If Err.Number <>
0 Then  
WScript.Echo "Please install SciTE Helper before!"  
WScript.Quit 1  
End If  
 
selected = True  
text = SciTE.GetSelText  
If text = "" Then  
Set
Args = WScript.Arguments  
If Args.Count < 1 Then  
MsgBox
(
"Неверные настройки запуска скрипта")  
WScript.Quit  
Else  
If not
fso.FileExists (Args(0)) Or fso.FolderExists (Args(0)) Then  
MsgBox
(
"Файл не найден - " & Args(0))  
WScript.Quit  
End If  
End If  
text = ReadFile (Args(0))  
selected = False  
End If  
 
' Подхват паттернов  
If fso.FileExists ("recent_search.txt") Then  
patrns = ReadFile ("recent_search.txt")  
first_pattern = rex_replace (patrns, "^([^\r\n]*)\r?\n?.*$", "$1")  
second_pattern = rex_replace (patrns, "^([^\r\n]*)\r?\n?(.*)$", "$2")  
End If  
 
find_string = InputBox("Enter pattern to search", "", first_pattern)  
If
find_string = "" Then WScript.Quit  
replace_string = InputBox("Enter pattern to replace with", "", second_pattern)  
' Передача в консоль количества вхождений  
WScript.Echo ( vbCRLF & " КОЛИЧЕСТВО ВХОЖДЕНИЙ: " & rex_find (text, find_string) & vbCRLF)  
text = rex_replace (text, find_string, replace_string)  
 
If
Selected Then  
SciTE.ReplaceSel (text)  
Else  
' SciTE.MenuCommand (207)  
' SciTE.ReplaceSel (text)  
WriteFile text, Args(0)  
WScript.Sleep (30)  
Scite.MenuCommand (104)  
End If  
 
' Сохранение паттернов  
patrns = find_string & vbCRLF & replace_string  
WriteFile patrns, "recent_search.txt"  
 
Function rex_replace(str1,patrn, replStr)  
Dim
regEx  
Set regEx = New RegExp  
regEx.Pattern = patrn  
regEx.IgnoreCase = True  
regEx.Global = True  
rex_replace = regEx.Replace(str1, replStr)  
End Function  
 
Function
rex_find (strng, patrn)  
Dim
regEx, Match, Matches, i  
Set regEx = New RegExp  
regEx.Pattern = patrn  
regEx.IgnoreCase = True  
regEx.Global = True  
Set
Matches = regEx.Execute (strng)  
For Each
Match in Matches  
i = i + 1  
Next  
rex_find = i  
End Function  
 
Sub
WriteFile(text, filename)  
Dim
File  
Const ForReading = 1, ForWriting = 2, ForAppending = 8  
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0  
Const CreateFile = True, DoNotCreateFile = False  
 
Set
fso = CreateObject("Scripting.FileSystemObject")  
Set
File = fso.OpenTextFile(filename, ForWriting, CreateFile)  
File.Write text  
File.Close  
End Sub  
 
Function
ReadFile(filename)  
Dim
File  
Const ForReading = 1, ForWriting = 2, ForAppending = 8  
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0  
Const CreateFile = True, DoNotCreateFile = False  
If
fso.FileExists(filename) Then  
If
fso.GetFile(filename).Size > 0 Then  
Set
File = fso.OpenTextFile(filename, ForReading, DoNotCreateFile, TristateUseDefault)  
ReadFile = File.ReadAll  
File.Close  
End If  
End If  
End Function  
 

Всего записей: 160 | Зарегистр. 05-01-2009 | Отправлено: 08:19 17-04-2010
   

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Программы » SciTE - Open Source Text Editor for Windows & Linux
Widok (23-11-2010 11:23): Лимит страниц. Продолжаем здесь


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru