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

Компьютерный форум OSzone.net » Программирование, базы данных и автоматизация действий » Скриптовые языки администрирования Windows » VBS/WSH/JS - [решено] путь к файлу

Ответить
Настройки темы
VBS/WSH/JS - [решено] путь к файлу

Старожил


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

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


скрипт
читать дальше »

option explicit
'original download code by ilboso http://www.srware.net/forum/viewtopic.php?f=18&t=1971
' -----------------------------------------------------------------------------
' PARAMETERS
' -----------------------------------------------------------------------------
const source = "https://secure.fanboy.co.nz/opera/urlfilter.ini" 'Opera list, for Iron list use "https://secure.fanboy.co.nz/iron/adblock.ini"
const destination = "C:\Program Files\SRWare Iron\adblock.ini" 'for 64bit use : "C:\Program Files (x86)\SRWare Iron\adblock.ini" or similar
const myfilter = "C:\Program Files\SRWare Iron\myfilter.txt" 'List with your own links, if you dont want this use: ""
' -----------------------------------------------------------------------------

' download adblock.ini
GetHtmlPage source, destination

' Replace code for Opera List
Operastuff destination, "*", ""
Operastuff destination, "#", "# "

' Add your own adblock's from myfilter file
Mylist destination, myfilter

' show message
dim s : s = ReadFirstLines(destination, 3)
dim fso, File
Dim WshShell
Set WshShell = CreateObject("WScript.Shell")
WshShell.popup s, 3, "Adblock.ini updated", 64


sub GetHtmlPage (up_http, down_http)

dim xmlhttp : set xmlhttp = createobject("msxml2.xmlhttp.3.0")
xmlhttp.open "get", up_http, false
xmlhttp.send

dim fso : set fso = createobject ("scripting.filesystemobject")
dim newfile : set newfile = fso.createtextfile(down_http, true)

'and the text from the XMLHTTP response can then be written to the file:
newfile.write (xmlhttp.responseText)

'the file must then be closed:
newfile.close

set newfile = nothing
set xmlhttp = nothing
set fso = nothing

end sub

sub Operastuff (fileName, Replace1, Replace2)

' Replace code for Opera List
Dim fsodat : Set fsodat = CreateObject("Scripting.FileSystemObject")
Dim T1 : T1 = fsodat.OpenTextFile(fileName).ReadAll
fsodat.CreateTextFile(fileName).Write Replace(T1, Replace1, Replace2)
set fsodat = nothing

end sub

sub Mylist (adfilter, linklist)

' Add your own adblock's from myfilter file
Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
IF objFSO.FileExists(linklist) THEN
Dim objTextFile : Set objTextFile = objFSO.OpenTextFile(linklist, 1)
Dim strText : strText = objTextFile.ReadAll
Dim AdFile : Set AdFile = objFSO.OpenTextFile(adfilter, 8)
AdFile.WriteLine strText
AdFile.Close
ELSE 'wscript.echo "Sorry, the myfilter file does not exist"
END IF
set objFSO = nothing

end sub

function ReadFirstLines(fileName, numberOfLines)

const wChar = "§"
dim res

' open text file
dim fso : set fso = createobject ("scripting.filesystemobject")
dim ts : set ts = fso.OpenTextFile(fileName)

' read the first x lines
dim x
for x = 1 to numberOfLines
res = res & ts.ReadLine & wChar
next

ts.close
set ts = Nothing
set fso = Nothing

' format output string
if len(res) > 1 then
res = left(res, len(res) - 1)
res = replace(res, wChar, vbCrlf)
end if

ReadFirstLines = res

end function

как, уйти от полных путей в
const destination = "C:\Program Files\SRWare Iron\adblock.ini"
const myfilter = "C:\Program Files\SRWare Iron\myfilter.txt"
если:- скрипт, adblock.ini, myfilter.txt - лежат в одной папке?

Отправлено: 12:51, 18-07-2011

 

Аватара для root221

Старожил


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

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


const destination = "adblock.ini"
const myfilter = "myfilter.txt"

или

const destination = "\adblock.ini"
const myfilter = "\myfilter.txt"

или

const destination = "..\adblock.ini"
const myfilter = "..\myfilter.txt"
Это сообщение посчитали полезным следующие участники:

Отправлено: 12:54, 18-07-2011 | #2



Для отключения данного рекламного блока вам необходимо зарегистрироваться или войти с учетной записью социальной сети.

Если же вы забыли свой пароль на форуме, то воспользуйтесь данной ссылкой для восстановления пароля.


Старожил


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

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


Цитата root221:
const myfilter = "..\myfilter.txt" »
Кажется вы немного ошиблись, две точки - это папка на уровень вверх, та же самая папка - это
Код: Выделить весь код
const myfilter = ".\myfilter.txt"
Это сообщение посчитали полезным следующие участники:

Отправлено: 16:05, 18-07-2011 | #3



Компьютерный форум OSzone.net » Программирование, базы данных и автоматизация действий » Скриптовые языки администрирования Windows » VBS/WSH/JS - [решено] путь к файлу

Участник сейчас на форуме Участник сейчас на форуме Участник вне форума Участник вне форума Автор темы Автор темы Шапка темы Сообщение прикреплено

Похожие темы
Название темы Автор Информация о форуме Ответов Последнее сообщение
CMD/BAT - [решено] BAT to EXE Не может определить путь к файлу men232 Скриптовые языки администрирования Windows 4 07-10-2010 20:09
C/C++ - Обьекты,Form, путь к файлу. K1nDeR45 Программирование и базы данных 0 06-10-2010 12:08
Добавление двойных кавычек в путь к файлу Karat19 AutoIt 6 04-11-2009 11:45
[решено] Как в программе прописать путь к языковому файлу? dima1981 Хочу все знать 3 16-05-2009 14:16
[решено] Службы, как сменить путь к исполнимому файлу?? masus Microsoft Windows 2000/XP 2 12-05-2006 00:39




 
Переход