お前ら、wsh使ってますか?

このエントリーをはてなブックマークに追加
53611
>>535
あっちのすれは盛り上がりに欠けるが、スクリプト使いのみなさまは
ぜひフォルダカスタマイズにも、チャレンジしていただきたいですね。

WSHから、表示中のフォルダのHTML(*.htt)の内容を取りだすこともできるし、
*.httで宣言されている関数を実行することもできるし、
*.httで使われているコントロールをWSHから呼び出して使うと
便利だったりするし、両者は結構、密接な関係にあるのです。

参考例。
'30日以内に更新されたファイルを選択
Set Shell = WScript.CreateObject("Shell.Application")
For Each window In Shell.Windows
Set document=window.document
If typename(document)="IShellFolderViewDual" Then
Set oFolder = document.Folder
Set oFolderItems = oFolder.Items
For Each oFolderItem In oFolderItems
If DateDiff("d",oFolderItem.ModifyDate,Now)<=30 Then
document.SelectItem oFolderItem,1 '選択
Else
document.SelectItem oFolderItem,0 '選択解除
End If
Next
window.StatusText="30日以内に更新された" & _
document.SelectedItems.Count & "個のオブジェクトを選択"
End If
Next
53711:02/03/02 02:23
参考例その2
'あるフォルダ内に含まれる複数ファイルをごみ箱に移す
MoveFilesToRecycleBin "C:\test",Array("testfile1.txt","testfile2.txt","testfile3.txt")

Sub MoveFilesToRecycleBin(Folder,Files)
Set Ie = WScript.CreateObject("InternetExplorer.Application")
Ie.Navigate Folder
Do While Ie.Busy Or Ie.ReadyState<>4
WScript.Sleep 10
Loop
Set document=Ie.Document
Set oFolder = document.Folder
Set oFolderItems = oFolder.Items
For Each oFolderItem In oFolderItems
For Each sFileName In Files
If LCase(oFolderItem.Name) = LCase(sFileName) Then
document.SelectItem oFolderItem,1
Exit For
Else
document.SelectItem oFolderItem,0
End If
Next
Next
document.SelectedItems.InvokeVerbEx "delete"
Ie.Quit
End Sub
53811:02/03/02 02:26
参考例その3
'表示中のフォルダのHTMLソース表示。
Set oShell = CreateObject("Shell.Application")
For Each oWindow In oShell.Windows
Set oDocument=oWindow.document
If TypeName(oDocument)="HTMLDocument" Then
msgbox oDocument.body.parentElement.outerHTML,,oWindow.LocationURL
ElseIf TypeName(oDocument)="IShellFolderViewDual" Or _
TypeName(oDocument)="WebViewFolderContents" Then
msgbox oDocument.Script.document.body.parentElement.outerHTML,, _
oDocument.Folder.Items.Item.Path
End If
Next
53911:02/03/02 02:28
参考例その4
'misc。何が起こるかはコメント行参照。
On Error Resume Next
Set Shell = WScript.CreateObject("Shell.Application")
For Each window In Shell.Windows
Set document=window.document
If typename(document)="IShellFolderViewDual" Then
Set oScript = document.Script 'HTMLWindow2オブジェクトを返す
If document.Folder.title="ごみ箱" Then
msg=msgbox (oScript.L_Intro_Text & vbCrLf & "ゴミ箱を空にしますか?", _
vbYesNo) '変数の表示
If msg=vbYes Then Call oScript.Empty '関数の実行
Else
msgbox oScript.Info.InnerText '情報ペインに表示されている内容を表示
oScript.FolderName.InnerText="WSHからのいたずら" 'フォルダ名を書き換える
oScript.window.document.body.style.color="red" '文字を赤に(スタイルの変更)
End If
End If
Next