Zasfe
Zasfe's memory
Zasfe
전체 방문자
오늘
어제
  • 분류 전체보기 (143)
    • 이야기 (50)
    • 뜻알기 (1)
    • 컴퓨터 (91)

인기 글

최근 글

태그

  • error
  • webhacking
  • web.config
  • webknight 2.2
  • 보안
  • Castle
  • ASP
  • 배치파일
  • 캐슬
  • 저장프로시저
  • IIS7
  • 홈페이지 보안 강화도구
  • backup
  • Security
  • MSSQL2K
  • webshell
  • webknight2.2
  • 생각
  • rsync
  • Microsoft Windows 2000 Scripting Guide
  • Function
  • Autoit
  • nslookup
  • webknight
  • Skin
  • webknight2.1
  • IIS
  • VBScript
  • MSSQL
  • cmd
hELLO · Designed By 정상우.
Zasfe

Zasfe's memory

컴퓨터

[Script Tip] 폴더 용량 한꺼번에 구하기

2007. 10. 4. 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
[Virtual Server 2005 R2] 설치 절차  (0) 2007.09.22
Windows Shell Hacking ...1  (0) 2007.09.05
Office XP 한글 입력기 2002 한영 전환 문제  (0) 2007.08.23
    '컴퓨터' 카테고리의 다른 글
    • [MSSQL] 엔터프라이즈 메니져의 접속시간을 줄여보자
    • Windows Fundamentals for Legacy PCs ( WInFLP ) 사용기
    • [Virtual Server 2005 R2] 설치 절차
    • Windows Shell Hacking ...1
    Zasfe
    Zasfe
    느낌. 기억

    티스토리툴바