フォルダーの .Size プロパティはその場で計算されます。したがって、そのサブツリーのすべての枝と葉は、操作の成功にとって重要です。私の C:\ には隠しシステム フォルダ "System Volume Information" が含まれており、.Name は取得できますが、.Size は取得できません:
>> sFP = "System Volume Information"
>> If goFS.FolderExists(sFP) Then WScript.Echo goFS.GetFolder(sFP).Name
>>
System Volume Information
>> If goFS.FolderExists(sFP) Then WScript.Echo goFS.GetFolder(sFP).Size
>>
Error Number: 70
Error Description: Permission denied
「許可が拒否されました」が「パスが見つかりません」ではないことは認めますが、一部のサブフォルダーの属性または許可が原因である可能性が高いようです。
アップデート
テストのために、e:\bin としてマップされている Linux 共有のフォルダーを台無しにするようルートに依頼しました。ルートは次を参照します。
bin
[-rwx------ eh 16] bin/dragit-ssh.sh
[lrwxrwxrwx eh 33] bin/komodo -> /home/eh/Komodo-Edit-6/bin/komodo
[drwxr-xr-x eh 4.0K] bin/pics
[-rwxr--r-- eh 6.0K] bin/pics/Thumbs.db
[-rwxr--r-- eh 20K] bin/pics/jsa.JPG
[-rwx------ root 10K] bin/pics/x
[-rwxr-xr-x eh 45] bin/rhinos.sh
[drwx------ root 4.0K] bin/rootsown
[-rwxr-xr-x root 10K] bin/rootsown/x
[-rwx------ eh 523] bin/showpath.sh
[-rwxr--r-- eh 325] bin/sp6p.sh
2 directories, 9 files
14392 /home/eh/bin/rootsown
40595 /home/eh/bin/pics
60025 /home/eh/bin
Linuxでは、私は見ることができます:
bin
[-rwx------ eh 16] bin/dragit-ssh.sh
[lrwxrwxrwx eh 33] bin/komodo -> /home/eh/Komodo-Edit-6/bin/komodo
[drwxr-xr-x eh 4.0K] bin/pics
[-rwxr--r-- eh 6.0K] bin/pics/Thumbs.db
[-rwxr--r-- eh 20K] bin/pics/jsa.JPG
[-rwx------ root 10K] bin/pics/x
[-rwxr-xr-x eh 45] bin/rhinos.sh
[drwx------ root 4.0K] bin/rootsown [error opening dir]
[-rwx------ eh 523] bin/showpath.sh
[-rwxr--r-- eh 325] bin/sp6p.sh
2 directories, 8 files
4096 bin/rootsown
40595 bin/pics
49729 bin
2 つの重要な事実: rootsown ディレクトリを「調べる」ことは許可されていないため、bin/rootsown/x を確認したりサイズを変更したりすることはできません。bin/pics/x のサイズは秘密ではありませんが、読み取り、変更、または実行は禁じられています。
VB スクリプト:
>> sf = "e:\bin\pics"
>> WScript.Echo goFS.GetFolder(sf).Size
>>
36499
厄介なファイルを含むフォルダーのサイズを取得できます。
>> sf = "e:\bin"
>> WScript.Echo goFS.GetFolder(sf).Size
>>
Error Number: 70
Error Description: Permission denied
厄介なサブ (サブ...) フォルダーを含むフォルダーの .Size を取得することはできません。
>> sf = "e:\bin\pics\rootsown"
>> WScript.Echo goFS.GetFolder(sf).Size
>>
Error Number: 76
Error Description: Path not found
厄介なフォルダーのサイズを尋ねると、「パスが見つかりません」というエラーが表示されます
これに基づいて、私はピーターの賭けを喜んで引き受けます。ファイルの属性またはアクセス許可を変更することでそれを示すことができれば、親フォルダーの .Size を成功させることができます。失敗したら、次に会うホームレスの人に 10 ユーロ払います。
控えめなディレクトリ:
フォルダーのサイズを取得するには、最初に試します
dir /s e:\bin
Volume in drive E is eh
Volume Serial Number is 0ED6-233C
Directory of e:\bin
4.06.2012 18:42 <DIR> .
4.06.2012 08:04 <DIR> ..
2.01.2012 12:21 45 rhinos.sh
3.06.2012 22:55 <DIR> rootsown
3.10.2011 16:42 325 sp6p.sh
4.06.2012 19:46 <DIR> pics
1.07.2010 23:34 523 showpath.sh
8.10.2010 16:57 582 komodo
4.05.2010 12:53 16 dragit-ssh.sh
5 File(s) 1.491 bytes
Directory of e:\bin\pics
4.06.2012 19:46 <DIR> .
4.06.2012 18:42 <DIR> ..
5.08.2011 10:22 10.296 x
0.07.2008 03:44 6.144 Thumbs.db
9.06.2012 23:29 20.059 jsa.JPG
3 File(s) 36.499 bytes
Total Files Listed:
8 File(s) 37.990 bytes
6 Dir(s) 29.060.050.944 bytes free
dir は、私が知ることが許されていることを知っているようで、厄介なフォルダーによって過度に妨げられていないようです。
dir を使用するスクリプト:
Option Explicit
Dim reX : Set reX = New RegExp
reX.Pattern = "Directory\s+of\s+(.+?)\r[\s\S]+?Total[\s\S]+?([.\d]+\sbytes)"
Dim oMTS : Set oMTS = reX.Execute(WScript.StdIn.ReadAll())
If 1 = oMTS.Count Then
WScript.Echo "Size of", oMTS(0).SubMatches(0), "=>", oMTS(0).SubMatches(1)
Else
WScript.Echo "Bingo!"
End If
サンプル使用:
dir /s e:\bin | cscript folsiz2.vbs
Size of e:\bin => 37.990 bytes
RegExp パターンは以下を検索します
Directory\s+of\s+ The first "Directory of "
(.+?) capture the path of the folder, that is
the sequence of 'everything except \n' but non greedy, so
\r the first \r will not be included in the capture
[\s\S]+? non greedy sequence of 'really everything (space or non-space)'
Total until "Total" is found
[\s\S]+? advance but stop for the first
([.\d]+\sbytes) sequence of . or digits followed by " bytes", capture
that because that is the first sum after Total