Petri.com forums Home Forums Start Page Forums Frequently Asked Questions FAQ Member List Members List
Go Back   Petri IT Knowledgebase Forums > Windows Scripting > General Scripting
Petri.com is happy to award RicklesP the title of Most Valuable Member !!!
Register Calendar Calendar Search Petri IT Knowledgebase Forums Search Todays Posts Today's Posts Mark Forums Read
Notices

Script to Report My Documents Size

Script to Report My Documents Size

this thread has 10 replies and has been viewed 7248 times

Closed Thread
 
Thread Tools Search this Thread Display Modes
  #1  
Old 20th March 2009, 23:47
shanehicks shanehicks is offline
Casual
Casual
 
 Join Date: Oct 2008
  6 month star 12 month star
 Posts: 9
 Reputation: shanehicks is on a distinguished road (10)
Default Script to Report My Documents Size

Hi everyone,
We are moving all of users my documents to a network share. Before we do, I need to find out how much space I need. Is there a way to script the my documents size and report it to a text document that keeps track of size.

Some caveats:
1. Only report once. I can do this by setting an IF statement and copying a file down after reporting.
2. I do not care about My Pictures or My Music. The script needs to exclude these directories.

Any help would be appreciated.
  #2  
Old 21st March 2009, 23:47
ekrengel ekrengel is offline
Member
Here to help
 
 Join Date: Jul 2006
  6 month star 12 month star
 Posts: 437
 Reputation: ekrengel will become famous soon enough (60)
Default Re: Script to Report My Documents Size

I'm not really sure how this would work, just because of the excluding part kindof throws me off, but it's an idea. I haven't tested...try this:

http://www.codingforums.com/showthread.php?t=68639

Code:
Set objNetwork = CreateObject("WScript.Network")
strUser = objNetwork.UserName
strPath = "C:\Documents and Settings\" & strUser & "\My Documents"
strLogFile = "C:\log.txt"
arrExclude = ("My Pictures", "My Videos")
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strLogFile, 8)
	If objFSO.FolderExists(strPath) Then
		GetSize(strPath)
		objFile.WriteLine "My Documents size for " & strUser & " : " & intSizeTotal
	Else
		objFile.WriteLine "My Documents does not exist!"
		WScript.Quit
	End If

Function GetSize(strPath)
	Set objFolder = objFSO.GetFolder(strPath)
		For Each File in objFolder.Files
			For i = lbound(arrExclude) to ubound(arrExclude)
			   Exclude = False
				If file.name = arrEclude(i) Then
					Exclude = True
				End If
			Next
				If Exclude = False then
					objFolder.Size = intSize
				End If
		intSizeTotal = intSizeTotal + intSize
		Next
End Function

objFile.Close

WScript.Quit(0)

Last edited by ekrengel; 22nd March 2009 at 00:02..
  #3  
Old 22nd March 2009, 00:43
ekrengel ekrengel is offline
Member
Here to help
 
 Join Date: Jul 2006
  6 month star 12 month star
 Posts: 437
 Reputation: ekrengel will become famous soon enough (60)
Default Re: Script to Report My Documents Size

Actually this might be much easier:

Code:
Set objNetwork = CreateObject("WScript.Network")
strUser = objNetwork.UserName
strDocuments = "C:\Documents and Settings\" & strUser & "\My Documents"
strMusic = "C:\Documents and Settings\" & strUser & "\My Documents\My Music"
strPictures = "C:\Documents and Settings\" & strUser & "\My Documents\My Pictures"
strLogFile = "C:\log.txt"
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.OpenTextFile(strLogFile, 8)
	If objFSO.FolderExists(strDocuments) Then
		Set objDocuments = objFSO.GetFolder(strDocuments)
		Set objMusic = objFSO.GetFolder(strMusic)
		Set objPictures = objFSO.GetFolder(strPictures)
			intSizeTotal = (objDocuments.Size - (objMusic.Size + objPictures.Size))
		objFile.WriteLine "My Documents size for " & strUser & " : " & intSizeTotal
	Else
		objFile.WriteLine "My Documents does not exist!"
		WScript.Quit
	End If

objFile.Close

WScript.Quit(0)
  #4  
Old 22nd March 2009, 11:35
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Script to Report My Documents Size

Yes that will do the job, getting the total size of the users's My Documents and subtract the sizes of the special folders that are found in the folder

Here is a similar vbscript.
Basically the main difference between this script and ekrengel's script is that it determine the actual path of the special folders first (is also OS language independed).

Code:
Const CSIDL_MY_DOCUMENTS = &H5&
Const CSIDL_MY_MUSIC = &Hd&
Const CSIDL_MY_PICTURES = &H27&
Const CSIDL_MY_VIDEOS = &He&
Const ForAppending = 8
Dim objShell

Set objShell = CreateObject("Shell.Application")
Set fso = CreateObject("scripting.filesystemobject")
Set WshNetwork = WScript.CreateObject("WScript.Network")

OutputName = WshNetwork.computername & "_" & WshNetwork.userdomain & "#" & WshNetwork.username
OutputPath = "C:\test"

'# Quit the script if file exist already
If fso.FileExists(OutputPath & "\" & OutputName & ".csv") Then wscript.quit

'# Determine the path and size of the users's domuments folder
MY_DOCUMENTS = GetSpecialFolder(CSIDL_MY_DOCUMENTS)
With fso.getfolder(MY_DOCUMENTS)
   FolderSize = .size
End With

On Error Resume Next
'# Subtract the sizes of the following 3 special folders
'# If they are a subfolder of the My Domuments folder

  Set re = new regexp : re.IgnoreCase = true
  strRoot = Replace(MY_DOCUMENTS,"\","\\")
  re.Pattern = "^(" & strRoot & "\\)"

MY_MUSIC = GetSpecialFolder(CSIDL_MY_MUSIC)
   If re.Test(MY_MUSIC) = True Then
      With fso.getfolder(MY_MUSIC)
         FolderSize = FolderSize - .size
      End With
   End If

MY_PICTURES = GetSpecialFolder(CSIDL_MY_PICTURES)
   If re.Test(MY_PICTURES) = True Then
      With fso.getfolder(MY_PICTURES)
         FolderSize = FolderSize - .size
      End With
   End If

MY_VIDEOS = GetSpecialFolder(CSIDL_MY_VIDEOS)
   If re.Test(MY_VIDEOS) = True Then
      With fso.getfolder(MY_VIDEOS)
         FolderSize = FolderSize - .size
      End With
   End If
On Error Goto 0

rem Set objNewFile = fso.CreateTextFile(strFile)
Set objLogFile = fso.OpenTextFile (_
   OutputPath & "\" & OutputName & ".csv", ForAppending, True)
   
objLogFile.writeline OutputName & "," & FolderSize & ",bytes"
objLogFile.close : Set objLogFile = Nothing

rem Wscript.Echo "Done,",_
rem      vbnewline & "My Documents FolderSize is", FolderSize, "bytes"
wscript.quit 0

Function GetSpecialFolder(sfolder)
   With objShell
      With .Namespace(sfolder)
         GetSpecialFolder = .Self.Path
      End With
   End With
End Function
It will write to a computer+user unique log file. If the log file exist already the script will not rewriting or appending to the previous file, the script will just quit.

Later on you can merge all single files to one csv file and calculate the total size.


\Rems
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts
  #5  
Old 23rd March 2009, 17:10
ekrengel ekrengel is offline
Member
Here to help
 
 Join Date: Jul 2006
  6 month star 12 month star
 Posts: 437
 Reputation: ekrengel will become famous soon enough (60)
Default Re: Script to Report My Documents Size



I think I've learned more from Rems than my teachers in school.
  #6  
Old 24th March 2009, 18:52
shanehicks shanehicks is offline
Casual
Casual
 
 Join Date: Oct 2008
  6 month star 12 month star
 Posts: 9
 Reputation: shanehicks is on a distinguished road (10)
Default Re: Script to Report My Documents Size

That works perfect. Thank You, Thank You!

I always praise this site to my coworkers!
  #7  
Old 29th April 2009, 00:16
kfo4 kfo4 is offline
Casual
Casual
 
 Join Date: Apr 2009
  6 month star 12 month star
 Posts: 1
 Reputation: kfo4 is on a distinguished road (10)
Default Re: Script to Report My Documents Size

I apologize for the question but will this script check my entire network or only my local machine?
  #8  
Old 29th April 2009, 00:29
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Script to Report My Documents Size

Quote:
Originally Posted by kfo4 View Post
I apologize for the question but will this script check my entire network or only my local machine?
Only the My documents folder of the current user on this computer.


\Rems
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts
  #9  
Old 19th May 2009, 13:45
Kelias Kelias is offline
Casual
Casual
 
 Join Date: May 2009
  6 month star 12 month star
 Posts: 2
 Reputation: Kelias is on a distinguished road (10)
Default Re: Script to Report My Documents Size

Thanks for the script Rems, just what i was looking for, however on Vista Ent. i recieve an error on Line: 35 Char: 4

Which is here:

....
With fso.getfolder(MY_DOCUMENTS)
->FolderSize = .size
....

Any info for me on that?

Edit: UAC disabled, user is Local Admin.

Last edited by Kelias; 19th May 2009 at 13:54.. Reason: More info.
  #10  
Old 19th May 2009, 14:05
Rems's Avatar
Rems Rems is offline
Moderator
 
 Join Date: Mar 2005
  6 month star 12 month star
 Location: NL
 Posts: 2,431
 Reputation: Rems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to beholdRems is a splendid one to behold (965)
Default Re: Script to Report My Documents Size

Are you sure that you showed the line that raised the error? You showed line 21 from the sample.

At line 35 there is:
..........MY_MUSIC = GetSpecialFolder(CSIDL_MY_MUSIC)
..........If re.Test(MY_MUSIC) = True Then
.............With fso.getfolder(MY_MUSIC)
35,4 -->....FolderSize = FolderSize - .size
.............End With
..........End If

Perhaps you have made changes to the script?


\Rems


EDIT
After running some tests it can be concluded that the script will not run on Windows Vista and newer Windows OSs. The ".Size" Property will return an "Access Denied" on any folder. Also, when you would use WMI the FileSize property of the Win32_Directory class that does not work either.
__________________

This posting is provided "AS IS" with no warranties, and confers no rights.

__________________

** Remember to give credit where credit's due **
and leave Reputation Points for meaningful posts

Last edited by Rems; 19th May 2009 at 21:23..
Closed Thread


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Script / report that finds mailbox access info? Wired General Scripting 4 24th February 2009 19:09
VB Script for prints report in print server pradeepbisht1983 General Scripting 3 12th December 2008 13:56
Exchange Relay List - Change vbs script report to text file? AndyJG247 General Scripting 3 13th November 2008 00:55
Script to report on current mapped drive connect Octagon General Scripting 10 11th April 2008 16:56
need a script for My Documents Redirection hshaik Windows 2000 Pro, XP Pro 3 4th April 2007 17:28


All times are GMT +3. The time now is 14:34.

Steel Blue 3.5.4 vBulletin Style ©2006 vBEnhanced
Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
 

Valid XHTML 1.0!   Valid CSS!

Copyright 2005 Daniel Petri