2014-03-05 3 views
0

폴더의 크기를 찾고 텍스트 상자에 크기 (KB)를 표시해야합니다.디렉토리 크기 얻기

아무도 내가이 작업을 수행하는 데 도움이 될 수 있으며 현재 내가 아래의 방법을 사용하려했지만 파일 크기가 아니라 폴더 크기를 찾을 수 있도록하며 KB 단위가 아닌 바이트 단위로만 표시합니다.

Dim infoReader As System.IO.FileInfo 
    infoReader = My.Computer.FileSystem.GetFileInfo("C:\imdb\bgs") 
    MsgBox("File is " & infoReader.Length & " bytes.") 
+0

해당 VBA입니까? VB.NET처럼 보입니다 – Brad

+0

또한 KB = 바이트 * 1024 – Brad

+0

이것은 VBA Brad입니다. – Aidan

답변

0

난 당신이 System.IO 어셈블리를 사용하는 방법에 분명 아니에요하지만 당신은 Microsoft Scripting Runtime (C : \ Windows \ SysWOW64 \에 Scrrun.dll에) 사용하는 경우에는 크기를 가지고 FolderFile 객체를 얻을 수 있습니다 속성은 바이트로 표시됩니다.

Dim fso As New FileSystemObject 
Dim sizeInBytes As Long 
sizeInBytes = fso.GetFolder("C:\imdb\bgs").Size 
Debug.Print sizeInBytes 
sizeInBytes = fso.GetFile("C:\imdb\bgs\.somefile.txt").Size 
Debug.Print sizeInBytes