顯示具有 vbscript 標籤的文章。 顯示所有文章
顯示具有 vbscript 標籤的文章。 顯示所有文章

2013年8月19日 星期一

命令列啟動瀏覽器,開啟多個分頁查詢關鍵字

在命令列下search.vbs 關鍵字
search.vbs的內容如下:
Dim ArgObj,sLine,sLinks
Dim ArgObj,sLine,sLinks
Set ArgObj = WScript.Arguments
Set WshShell = CreateObject("WScript.Shell")
sLinks="http://tw.search.yahoo.com/search?p=%s&fr=yfp&ei=utf-8&v=0 http://search.goo.ne.jp/web.jsp?MT=%s&STYPE=web&SH=1&IE=UTF-8&OE=UTF-8&from=gootop&bt_search.x=39&bt_search.y=11"
if ArgObj.length > 0 Then
 for i=0 to ArgObj.length-1 
  sLine=sLine & ArgObj(i) & "+"
 next 
 sLinks = Replace(sLinks,"%s",sLine)
End if
WshShell.Run "opera " & sLinks

sLinks變數可以新增網站,欲搜尋的文字用%s取代。舉例:欲新增Google網站,先搜尋關鍵字,後將網址列上的網址複製下來,即https://www.google.com.tw/search?q=%E9%97%9C%E9%8D%B5%E5%AD%97&oq=%E9%97%9C%E9%8D%B5%E5%AD%97&aqs=chrome.0.69i57j69i65j0l2j5j69i62.4506j0&sourceid=chrome&ie=UTF-8。將欲搜尋的文字用%s取代,得https://www.google.com.tw/search?q=%s&oq=%s&aqs=chrome.0.69i57j69i65j0l2j5j69i62.4506j0&sourceid=chrome&ie=UTF-8。最後,得到的網址就可以新增到sLinks變數中,字串中的每個網址以空白做分隔。

要啟動opera瀏覽器,首先確定你在命令列下可以找到它。啟動命令列,下opera指令。如果你得到下列的訊息,表示你無法啟動它。
D:\>opera
'opera' is not recognized as an internal or external command,
operable program or batch file.
也可以指定瀏覽器執行檔所在位置,來啟動瀏覽器。如果路徑中包含空白,請用雙雙引號""來包含它。舉例如下:
WshShell.Run """D:\Program Files\GoogleChromePortable2\App\Chrome-bin\chrome.exe"" " & sLinks

2011年11月12日 星期六

list all files

Code: VB
On Error Resume Next
Dim fso, folder, files, NewsFile,sFolder

Set fso = CreateObject("Scripting.FileSystemObject")
sFolder = Wscript.Arguments.Item(0)
If sFolder = "" Then
Wscript.Echo "No Folder parameter was passed"
Wscript.Quit
End If
Set NewFile = fso.CreateTextFile(sFolder&"\FileList.txt", True)
Set folder = fso.GetFolder(sFolder)
Set files = folder.Files

For each folderIdx In files
NewFile.WriteLine(folderIdx.Name)
Next
NewFile.Close

Example usage:
Code:
lister.vbs "c:\documents and settings"
http://www.go4expert.com/forums/showthread.php?t=927

read a file

Here is the code:


Option Explicit

Dim objFSO, strTextFile, strData, strLine, arrLines
CONST ForReading = 1

'name of the text file
strTextFile = "textfile.conf"

'Create a File System Object
Set objFSO = CreateObject("Scripting.FileSystemObject")

'Open the text file - strData now contains the whole file
strData = objFSO.OpenTextFile(strTextFile,ForReading).ReadAll

'Split the text file into lines
arrLines = Split(strData,vbCrLf)

'Step through the lines
For Each strLine in arrLines
wscript.echo strLine
Next

'Cleanup
Set objFSO = Nothing
http://hacktivision.com/index.php/2009/04/24/vbscript-to-read-a-text-file-line-by-lin?blog=2