{"id":70123,"date":"2005-03-31T12:58:00","date_gmt":"2005-03-31T12:58:00","guid":{"rendered":"https:\/\/blogs.technet.microsoft.com\/heyscriptingguy\/2005\/03\/31\/how-can-i-determine-the-size-of-the-my-documents-folder\/"},"modified":"2005-03-31T12:58:00","modified_gmt":"2005-03-31T12:58:00","slug":"how-can-i-determine-the-size-of-the-my-documents-folder","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/scripting\/how-can-i-determine-the-size-of-the-my-documents-folder\/","title":{"rendered":"How Can I Determine the Size of the My Documents Folder?"},"content":{"rendered":"<p><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Question\" border=\"0\" alt=\"Hey, Scripting Guy! Question\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/q-for-powertip.jpg\" width=\"34\" height=\"34\"> \n<P>Hey, Scripting Guy! How can I determine the size of the My Documents folder?<BR><BR>&#8212; SC<\/P><IMG border=\"0\" alt=\"Spacer\" src=\"https:\/\/devblogs.microsoft.com\/scripting\/wp-content\/uploads\/sites\/29\/2019\/05\/spacer.gif\" width=\"5\" height=\"5\"><IMG class=\"nearGraphic\" title=\"Hey, Scripting Guy! Answer\" border=\"0\" alt=\"Hey, Scripting Guy! Answer\" align=\"left\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/29\/2019\/02\/a-for-powertip.jpg\" width=\"34\" height=\"34\"><A href=\"http:\/\/go.microsoft.com\/fwlink\/?linkid=68779&amp;clcid=0x409\"><IMG class=\"farGraphic\" title=\"Script Center\" border=\"0\" alt=\"Script Center\" align=\"right\" src=\"http:\/\/img.microsoft.com\/library\/media\/1033\/technet\/images\/scriptcenter\/ad.jpg\" width=\"120\" height=\"288\"><\/A> \n<P>Hey, SC. The My Document folder is actually just another folder on the hard disk, one with a path similar to this: C:\\Documents and Settings\\kenmyer\\My Documents. Of course, the actual path will vary depending on the name of the logged-on user; in addition, the My Documents folder can be redirected to another location, which means it isn\u2019t necessarily in the C:\\Documents and Settings folder either. What we\u2019re trying to say is that the tricky part here is actually <I>finding<\/I> the My Documents folder; once you find it you can then use the <B>FileSystemObject<\/B> to determine the folder size (and we can do <I>that<\/I> because My Documents is, as we noted, just another folder on the hard disk).<\/P>\n<P>So how do we find the My Documents folder? Well, there are a couple ways to do this, but we\u2019re going to use the <B>Shell<\/B> object; that\u2019s because the Shell object can be used to find the path to all sorts of special folders, including My Pictures, My Music, My Network Places, etc. Here\u2019s a script that reports the size of the My Documents folder:<\/P><PRE class=\"codeSample\">Const MY_DOCUMENTS = &amp;H5&amp;<\/p>\n<p>Set objFSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)\nSet objShell = CreateObject(&#8220;Shell.Application&#8221;)<\/p>\n<p>Set objFolder = objShell.Namespace(MY_DOCUMENTS)\nSet objFolderItem = objFolder.Self\nstrPath = objFolderItem.Path<\/p>\n<p>Set objFolder = objFSO.GetFolder(strPath)\nWscript.Echo objFolder.Size\n<\/PRE>\n<P>We begin by defining a constant named MY_DOCUMENTS and assigning it the value &amp;H5&amp;, the value used by the Shell object to reference the My Documents folder. We then create two separate objects: objFSO (an instance of the FileSystemObject) and objShell (an instance of the Shell object).<\/P>\n<P>Now the fun begins. We use the <B>Namespace<\/B> method to bind to the My Documents folder and then use the <B>Self<\/B> property to create an object reference to the FolderItem object that represents My Documents. (We won\u2019t worry about why we have to do that; it\u2019s just something that the Shell object requires.) Finally, we store the value of the <B>Path<\/B> property (e.g., C:\\Documents and Settings\\kenmyer\\My Documents) into a variable named strPath.<\/P>\n<P>Still with us? Now that we know the path to the My Documents folder we can use the FileSystemObject and the <B>GetFolder<\/B> method to bind to My Documents. Yes, we already did this once, but that was with the Shell object. Now we have to repeat the process with the FileSystemObject. Why? Well, the Shell object can locate the My Documents folder for us, but can\u2019t report the folder size. The FileSystemObject can report the folder size, but can\u2019t locate the My Documents folder for us. Thus we have to use both objects to complete this single task.<\/P>\n<P>After we bind to My Documents using the FileSystemObject we can then echo the size of the folder using this line of code:<\/P><PRE class=\"codeSample\">Wscript.Echo objFolder.Size\n<\/PRE>\n<P>Granted, not the most straightforward process in the world but at least it returns the size of the My Documents folder. And that\u2019s all we really care about.<\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hey, Scripting Guy! How can I determine the size of the My Documents folder?&#8212; SC Hey, SC. The My Document folder is actually just another folder on the hard disk, one with a path similar to this: C:\\Documents and Settings\\kenmyer\\My Documents. Of course, the actual path will vary depending on the name of the logged-on [&hellip;]<\/p>\n","protected":false},"author":595,"featured_media":87096,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[40,11,3,12,5],"class_list":["post-70123","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-scripting","tag-filesystemobject","tag-folders","tag-scripting-guy","tag-storage","tag-vbscript"],"acf":[],"blog_post_summary":"<p>Hey, Scripting Guy! How can I determine the size of the My Documents folder?&#8212; SC Hey, SC. The My Document folder is actually just another folder on the hard disk, one with a path similar to this: C:\\Documents and Settings\\kenmyer\\My Documents. Of course, the actual path will vary depending on the name of the logged-on [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/users\/595"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/comments?post=70123"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/posts\/70123\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media\/87096"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/media?parent=70123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/categories?post=70123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/scripting\/wp-json\/wp\/v2\/tags?post=70123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}