フォルダの「総ファイルサイズ」と「ファイル数」カラムに値を設定、表示する。(その3)
親ディレクトリをドロップすると、子孫ディレクトリのすべてに設定します。ただし、アクセス許可のないものはスキップします。
FolderSize.vbs 親フォルダパス
Option Explicit
Dim fso
Set fso=CreateObject("Scripting.FileSystemObject")
Call TreeFolderSize(fso.GetFolder(WScript.Arguments.Item(0)))
Sub TreeFolderSize(Folder)
Dim SubFolder
On Error Resume Next
For Each SubFolder In Folder.SubFolders
Call TreeFolderSize(SubFolder)
Call FolderSize(SubFolder)
Next
End Sub
Sub FolderSize(Folder)
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
End Sub
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) | トップページ | バックスペース文字をバッチファイルで使う。 »