フォルダの「総ファイルサイズ」と「ファイル数」カラムに値を設定、表示する。(その2)
親フォルダをドロップすると、サブフォルダのdesktop.iniに「総ファイルサイズ」と「ファイル数」を設定します。
これでエクスプローラに表示されます。
この情報はエクスプローラプロセスにキャッシュされるため、設定し直しても表示に即反映されません。
フォルダ名を変えるか、エクスプローラを別プロセスで起動すれば、表示に反映されます。
explorer.exe /separate,フォルダ
FolderSize.vbs 親フォルダパス
Option Explicit
Dim fso
Dim Folder
Set fso=CreateObject("Scripting.FileSystemObject")
For Each Folder In fso.GetFolder(WScript.Arguments.Item(0)).SubFolders
Call UpdateIniFile(Folder.Path & "\desktop.ini","[{28636AA6-953D-11D2-B5D6-00C04FD918D0}]","Prop14=","21," & Folder.Size)
Call UpdateIniFile(Folder.Path & "\desktop.ini","[{28636AA6-953D-11D2-B5D6-00C04FD918D0}]","Prop12=","21," & FileCount(Folder))
If Not (Folder.Attributes And 1) Then Folder.Attributes=Folder.Attributes Or 1
Next
Sub UpdateIniFile(Path,Section,Name,Value)
Dim fso
Dim File
Dim Lines
Dim Line
Dim State
Set fso=CreateObject("Scripting.FileSystemObject")
Set Lines=CreateObject("Scripting.Dictionary")
Set File=fso.OpenTextFile(Path,1,True)
State=0
Do While Not File.AtEndOfStream
Line=File.ReadLine()
Select Case State
Case 0
If Line=Section Then State=1
Lines.Add Lines.Count,Line
Case 1
If Left(Line,1)="[" Then
State=2
Lines.Add Lines.Count,Name & Value
Lines.Add Lines.Count,Line
Else
If InStr(Line,Name)=1 Then
State=2
Lines.Add Lines.Count,Name & Value
Else
Lines.Add Lines.Count,Line
End If
End If
Case 2
Lines.Add Lines.Count,Line
End Select
Loop
If State=0 Then
Lines.Add Lines.Count,Section
Lines.Add Lines.Count,Name & Value
ElseIf State=1 Then
Lines.Add Lines.Count,Name & Value
End If
File.Close
Set File=fso.OpenTextFile(Path,2,True)
File.WriteLine Join(Lines.Items,vbCrLf)
File.Close
End Sub
Function FileCount(Folder)
Dim SubFolder
FileCount=Folder.Files.Count
For Each SubFolder In Folder.SubFolders
FileCount=FileCount+FileCount(SubFolder)
Next
End Function
« 「フォルダショートカット」を作る。(その2) | トップページ | フォルダの「総ファイルサイズ」と「ファイル数」カラムに値を設定、表示する。(その3) »