Visual Basic Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 6th, 2012, 05:12 PM
testerV testerV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 65 testerV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
Subfolders Path\Name\Size to text file

Hi,
I’m trying to write a code, it supposed to scan a folder for subfolders and print to a log file their Path\Folder name\Folder size.

I decided to get the subfolders names and the size and print it to a text file.
The code I got so far can echo Name&Size butit does not want to print it in to a text file.
Could you guys help me with this?
Thanks, testerV

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Sub_Dirsize.txt", True)


Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("C:\TestFiles")

for Each folder in objFolder.SubFolders
    On Error Resume Next
    size = folder.size
  if Err.Number <> 0 Then
        size = -1
objFile.WriteLine "folder.name,size "        
    end if
'    wscript.echo folder.name,size
    Next
   WScript.Quit

Reply With Quote
  #2  
Old November 6th, 2012, 05:48 PM
medialint's Avatar
medialint medialint is offline
Type Cast Exception
Dev Shed God 20th Plane (14500 - 14999 posts)
 
Join Date: Apr 2004
Location: OAKLAND CA | Adam's Point (Fairyland)
Posts: 14,938 medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)medialint User rank is General 112nd Grade (Above 100000 Reputation Level)  Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1Folding Points: 319635 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 6 Months 2 Weeks 2 Days 26 m 38 sec
Reputation Power: 8490
Facebook
Remove the quotes from the writeline (1) and take it out of the if conditional (2).

(1) You'd literally be writing what's in the quotes to the file thus it would literally look like
folder.name,size
folder.name,size
folder.name,size
folder.name,size
folder.name,size

(2) You'd only be writing a line if there was an error.
__________________
medialint.com

“Today you are You, that is truer than true. There is no one alive who is Youer than You.” - Dr. Seuss

Reply With Quote
  #3  
Old November 6th, 2012, 08:02 PM
Rukbat Rukbat is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 10 Rukbat User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 18 m 25 sec
Reputation Power: 0
Try it this way:

Code:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Sub_Dirsize.txt", True)


Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
set objFolder = objFSO.GetFolder("C:\TestFiles")

for Each folder in objFolder.SubFolders
    On Error Resume Next
    size = folder.size
    if Err.Number <> 0 Then size = -1
    On Error GoTo 0
    objFile.WriteLine folder.name,size         
Next
WScript.Quit

Reply With Quote
  #4  
Old November 6th, 2012, 11:14 PM
testerV testerV is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2012
Posts: 65 testerV User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 14 h 35 m 42 sec
Reputation Power: 1
Thank you medialint and Rukbat! You guys rock!
testerV

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreVisual Basic Programming > Subfolders Path\Name\Size to text file

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap