Zasfe's memory
느낌. 기억
Home
Location
Media
Tag
Guest
[Script Tip] 폴더 용량 한꺼번에 구하기
- 2007/10/04 05:10
/
윈도우
그동안 중요한 자료는 모두 USB에 담아가지고 다닙니다. 하지만 결코 작은 용량이 아닌 1G USB 디스크의 여유공간이 4mb 밖에 안남는 사태가 발생하고야 말았습니다.
그간 정리하는 습관과는 거리가 멀어 복사붙이기로 분류만 해두었는데 폴더는 점점 많아져서 정리의 엄두가 나지 않았습니다.
그러다 찾은것이 "getfoldersize.vbs"
오~ 완전 나이스..
게다가 결과물을 텍스트 파일이 아닌 엑셀로 만들어주기까지 한다.
소스 보기
'---------------------------------------------------------------------------------------
'
' Name: getfoldersize.vbs
' Version: 1.0
' Date: 7-5-2002
' Author: Hans van der Zaag
' Description: getfoldersize.vbs calculates the size of all subfolders within
' a folder and sorts this data in an excel workbook
'
'---------------------------------------------------------------------------------------
rootfolder = Inputbox("Enter directory/foldername: " & _
chr(10) & chr(10) & "(i.e. C:\Program Files or " & _
"
\\Servername\C$\Program
Files)" & chr(10) & chr(10), _
"Getfoldersize", "C:\Program Files")
outputfile = "c:\foldersize_" & Day(now) & Month(now) & Year(now) & ".xls"
Set fso = CreateObject("scripting.filesystemobject")
if fso.fileexists(outputfile) then fso.deletefile(outputfile)
'Create Excel workbook
set objXL = CreateObject( "Excel.Application" )
objXL.Visible = False
objXL.WorkBooks.Add
'Counter 1 for writing in cell A1 within the excel workbook
icount = 1
'Run checkfolder
CheckFolder (FSO.getfolder(rootfolder))
Dim tmpFolderSize
Sub CheckFolder(objCurrentFolder)
For Each objFolder In objCurrentFolder.SubFolders
FolderSize = objFolder.Size
' If objFolder.ParentFolder.Path"d:\hosting" then
Tmp = (FormatNumber(FolderSize, 0, , , 0)/1024)/1024
ObjXL.ActiveSheet.Cells(icount,1).Value = objFolder.Path
ObjXL.ActiveSheet.Cells(icount,2).Value = Tmp
WScript.Echo "CheckFolder : " & Tmp & " " & objFolder.Path
'raise counter with 1 for a new row in excel
icount = icount + 1
Next
End Sub
'sort data in excel
objXL.ActiveCell.CurrentRegion.Select
objXL.Selection.Sort objXL.Worksheets(1).Range("B1"), _
2, _
, _
, _
, _
, _
, _
0, _
1, _
False, _
1
'Lay out for Excel workbook
objXL.Range("A1").Select
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Selection.EntireRow.Insert
objXL.Columns(1).ColumnWidth = 60
objXL.Columns(2).ColumnWidth = 15
objXL.Columns(2).NumberFormat = "#,##0.0"
objXL.Range("B1:B1").NumberFormat = "d-m-yyyy"
objXL.Range("A1:B5").Select
objXL.Selection.Font.Bold = True
objXL.Range("A1:B3").Select
objXL.Selection.Font.ColorIndex = 5
objXL.Range("A1:A1").Select
objXL.Selection.Font.Italic = True
objXL.Selection.Font.Size = 16
ObjXL.ActiveSheet.Cells(1,1).Value = "Survey FolderSize "
ObjXL.ActiveSheet.Cells(1,2).Value = Day(now) & "-" & Month(now) & "-"& Year(now)
ObjXL.ActiveSheet.Cells(3,1).Value = UCase(rootfolder)
ObjXL.ActiveSheet.Cells(5,1).Value = "Folder"
ObjXL.ActiveSheet.Cells(5,2).Value = "Total (MB)"
'Finally close the workbook
ObjXL.ActiveWorkbook.SaveAs(outputfile)
ObjXL.Application.Quit
Set ObjXL = Nothing
'Message when finished
Set WshShell = CreateObject("WScript.Shell")
Finished = Msgbox ("Script executed successfully, results can be found in " & Chr(10) _
& outputfile & "." & Chr(10) & Chr(10) _
& "Do you want to view the results now?", 65, "Script executed successfully!")
if Finished = 1 then WshShell.Run "excel " & outputfile
하지만..
엑셀로 불러오는것보다 커맨드라인으로 바로바로 확인이 가능할거 같다는 생각을 하게되고 좀더 일반적인 환경에서 사용이 가능하도록 스크립트내에서 확인이 가능하도록 변경하였다.
■ 변경내용
- 커맨드라인에서 결과를 바로 확인할수 있도록 변경.
- 하위폴더까지 나오면서 폴더가 복잡한 구조에서는 보기도 힘들다.
- 파일용량을 보기 편한 단위로 변경할수 있도록
'
' cscript Get_folder_size_cmd.vbs
'
Dim CRLF, TAB :TAB = CHR( 9 ):CRLF = CHR( 13 ) & CHR( 10 )
Dim Tmp, totalsize
totalsize =0
rootfolder = "Z:\"
Set fso = CreateObject("scripting.filesystemobject")
'Run checkfolder
CheckFolder (FSO.getfolder(rootfolder))
wscript.echo "totalsize : "&int((FormatNumber(totalsize, 0, , , 0)/1024)/1024/1024) & " GB"
Sub CheckFolder(objCurrentFolder)
For Each objFolder In objCurrentFolder.SubFolders
If Instr(objFolder.Path,"RECYCLER") =0 and Instr(objFolder.Path,"System Volume Information") =0 then
FolderSize = objFolder.Size
totalsize = totalsize+FolderSize
Tmp = (FormatNumber(FolderSize, 0, , , 0)/1024)/1024
If int(Tmp)/1024 > 1 then
WScript.Echo objFolder.Path& TAB & int(Tmp)/1024 &" GB"
else
WScript.Echo objFolder.Path& TAB & int(Tmp) &" MB"
end if
end if
Next
End Sub
'
윈도우
' 카테고리의 다른 글
[MSSQL] 엔터프라이즈 메니져의 접속시간을 줄여보자
(2)
2007/10/11
Windows Fundamentals for Legacy PCs ( WInFLP ) 사용기
(0)
2007/10/04
[Script Tip] 폴더 용량 한꺼번에 구하기
(2)
2007/10/04
[Virtual Server 2005 R2] 설치 절차
(0)
2007/09/22
Windows Shell Hacking ...1
(0)
2007/09/05
Office XP 한글 입력기 2002 한영 전환 문제
(0)
2007/08/23
VBScript
Trackback(
0
)
:
Comment
(
2
)
Trackback Address ::
http://zasfe.com/trackback/52
Hoya~
| 2008/08/05 18:31 |
PERMALINK
|
EDIT/DEL
|
REPLY
재밌네요.ㅎㅎ
zasfe
| 2008/08/10 03:03 |
PERMALINK
|
EDIT/DEL
반복작업이 제일 귀찮은 작업이라 ㅋ
감사합니다.
Name
Password
Homepage
Secret
< PREV
|
1
|
...
95
|
96
|
97
|
98
|
99
|
100
|
101
|
102
|
103
|
...
135
|
NEXT >
Search |
Category
분류 전체보기
(135)
이야기
(42)
뜻알기
(1)
윈도우
(80)
블로그
(5)
보안글
(6)
Tags
VBScript
webknight
MSSQL
IIS
Microsoft Windows 2000 Scripting Guide
Security
ASP
Skin
보안
MSSQL2K
생각
webknight2.2
rsync
webhacking
xp
mssql 2000
배열
cmd
이벤트로그
registry
홈페이지 보안 강화도구
사용기
Autoit
웹해킹
backup
설치
PowerShell
IIS7
PSP
Castle
Recent Entries
25일에 대한 기록
윈도우 업데이트 에러 0x80..
(1)
IIS7 에서는 일반연결(http..
(1)
백업기록 조회
데이터베이스 간략정보 추..
Recent Trackbacks
삼성은 IBM에게 길을 물어..
16. garbage
가장 강력한 멀티 클립보드..
도아의 세상사는 이야기
구글, 표현의 자유를 존중?..
도아의 세상사는 이야기
실버라이트 xap 실행이 안..
위즈군의 라이프로그
고 노무현 대통령님의 조문..
♡바다.. 의 일상이야기
Archive
2011/12
2010/02
2010/01
2009/12
2009/08