4

特定のディレクトリ内の現在のフォルダーとサブフォルダーに関する情報を取得するスクリプトがあります。それはうまく機能しますが、私は奇妙な問題に出くわしました:

dim FSO, objFolder, datafolder, foldername, objSubfolder, totalSize
dim objSubfolder2, objFolder2, mSize, size, today, dateLastMod

foldername = "D:\folder\subfolder"
set FSO = CreateObject("Scripting.FileSystemObject")
set objFolder = FSO.GetFolder(foldername) 
set colSubfolders = objFolder.Subfolders
today = Now
ShowFolderDetails objFolder

Function ShowFolderDetails(oF)

    datafolder = oF.Size/1073741824
    wscript.echo oF.Name & " :Size= " & datafolder & " GB"
    wscript.echo oF.Name & " #Files= " & oF.Files.Count
    wscript.echo oF.Name & " #Folders= " & oF.Subfolders.count
    wscript.echo oF.Name & " Date Last Modified= " & oF.DateLastModified
    totalSize = totalSize + datafolder

end Function

従うべきことは他にもありますが、私の問題は、path not foundその関数を呼び出すときに を取得することです。

フォルダーは C:\ ドライブにありません。これは問題にはなりません。私はこれと同じスクリプトを実行しましたが、foldername = D:\folder\differentsubfolder完全に機能するものを変更しました。しかし、それを別のフォルダーに戻すと、パスが見つからないというエラーが表示されます。

また、set FSO = CreatObject("Scripting.FileSytemObject") 以下のすべてを IF ステートメント内に配置しようとしました。

IF FSO.FolderExists(フォルダ名) その後 ....

これその IF ステートメントに入力されるため、VBS がそれを認識していると思われますが、それでもエラーが発生しline 17 (datafolder = oF.Size/1073741824)ます。

変数フォルダー名が配置されている完全なフォルダーパスを入力しようとしました(引用符で囲まれています)。

他のディレクトリを指しているvbsを実行しようとしましたが、100%実行されます。その特定のフォルダーだけです。フォルダ名にスペースはありません。私が見逃しているものは他にありますか?D:\ への完全な管理者アクセス権があります

4

2 に答える 2

2

原因は隠しファイルやフォルダではないに違いありませんが、Thumbs.db thasなどのシステムファイルは画像を含む多くのフォルダにあります。フォルダオプションを編集してシステムファイルを表示し、システムファイルを削除して再試行してください。フォルダのサイズを尋ねるときは、その下にあるすべてのフォルダとファイルにアクセスする必要があります。プロファイルフォルダなどでスクリプトを試してみると、そのフォルダの管理者または所有者であるかどうかにかかわらず、間違いなくエラーが発生します。

それが役立つ場合は、ここでファイルから属性を与えるスクリプト

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.GetFile("c:\ruby193.zip")
If objFile.Attributes AND 0 Then
    Wscript.Echo "No attributes set."
End If    
If objFile.Attributes AND 1 Then
    Wscript.Echo "Read-only."
End If    
If objFile.Attributes AND 2 Then
    Wscript.Echo "Hidden file."
End If    
If objFile.Attributes AND 4 Then
    Wscript.Echo "System file."
End If    
If objFile.Attributes AND 32 Then
    Wscript.Echo "Archive bit set."
End If    
If objFile.Attributes AND 64 Then
    Wscript.Echo "Link or shortcut."
End If    
If objFile.Attributes AND 2048 Then
    Wscript.Echo "Compressed file."
End If
于 2012-06-14T15:53:14.400 に答える
1

フォルダーの .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
于 2012-06-13T20:43:29.117 に答える