InterviewSolution
Saved Bookmarks
| 1. |
Solve : Batch file to check the folder size? |
|
Answer» @sun_os: c:\document and setting\administrator: 10,182,572,281 MB Are you sure the 10,182,572,281 represents MB (which is an awful lot) or just bytes (more reasonable) It turns out that 10,182,572,281 bytes is 9710.8577 MB. Imagine that! The file size for both the onscreen display and the csv line are computed the same way. I cannot reproduce the error. Need more info. @nuckinfutz : Please start your own thread. This marathon thread has gone on for 29 posts with no end in sight. Your post is only complicating things. Hi Sidewinder, How can I start the New Thread here? Could you tell me, is that mean send you the personal messages ? I copy your code and run cscript //d check.vbs , check with csv format which is not match the console information Quote from: sun_os on July 20, 2010, 07:37:35 AM How can I start the New Thread here? That was for nuckinfutz who tried to hijack your thread. Quote from: sun_os on July 20, 2010, 07:37:35 AM Could you tell me, is that mean send you the personal messages ? No. I very rarely even check if I have messages much less answer them. I prefer to post solutions that everyone can read. Quote from: sun_os on July 20, 2010, 07:37:35 AM I copy your code and run cscript //d check.vbs , check with csv format which is not match the console information I cannot reproduce your results: Quote C:\Temp>cscript untitled.vbs Unless I'm missing something, the console and the csv file matches. The only difference is the format of the output, but the data is the same. You wanted a csv file (comma separated values). CSV files are useful when you need to input the data into a spreadsheet or database program. They are also easy to parse. Hi I capture the screen shot for your reference C:\temp>cscript check.vbs Microsoft (R) Windows Script Host Version 5.6 Copyright (C) Microsoft Corporation 1996-2001. All rights reserved. Please enter directory name: c:\downloads C:\Downloads: 5,203,235,307 MB C:\temp>type disk* 系統找不到指定的檔案。 C:\temp>type dir* DirSize.csv C:\Documents and Settings\Administrator,9710.8577 C:\Downloads,4962.1919 C:\Downloads,4962.1919 C:\temp> That is output ThanksPlease check your code. I'm not understanding any of this. It appears the line that produces the console output has a problem. The line produces the console output: Quote WScript.Echo f.Path & ": " & FormatNumber((f.Size / 1048576),4,,TriStateTrue) & " MB" This line produces the CSV file output: Quote fs.WriteLine f.Path & "," & Replace(FormatNumber((f.Size / 1048576),4), ",", "") Also check this line: Quote Set fs = fso.OpenTextFile("c:\temp\DirSize.csv", ForAppending, True)The above line shows the path to the CSV file. If you changed it that's fine as long as you know where the CSV file is. If this doesn't turn up anything, please post the script you are using. If you made any changes leave them in. Need to see the actual code that runs. Hi Sidewinder I run the same script on the another workstation, it is no problem on the size checking. I think something wrong on my workstation. Last time, I request to check the directory size, the code is FOCUS on that. If the script can let me check the size of drive or directory folder option. I need to use compond condition if....if.... then....elsif condition Thanks Quote from: sun_os on July 20, 2010, 08:59:56 PM Hi SidewinderGlad to see you got the script working. Not sure what could have caused the error on you other machine. VBScript is very forgiving where objects and variables are destroyed when the script ends. An exception is application objects (Word, Excel, etc) where they must be Quit, otherwise you'll find them in your task list long after the script ends. Quote Last time I have the problem on the script to do the check the size, but I get message from my boss, he needs to check the case is run the script can show all the size of directory at once. Not sure what you're asking. I tweaked the script to display the subfolders. I also added a unit of measure to the CSV file so the numbers make more sense. Be aware that the FileSystemObject recurses the directory tree when computing the size property. Each folder size includes all of it's subfolders. The numbers you see are correct but may appear inflated. It's possible to retrieve the files from a recursive folder search, but the total size of the files will probably not add up to the size of the folder unless the folder has no subfolders. This would be easier in BATCH, however batch arithmetic only deals with integers. This can lead to some wildly inaccurate results. Hey! 700k bytes here, 700k bytes there, and pretty soon you're talking about some serious real estate. Code: [Select]Const ForAppending = 8 Set fso = CreateObject("Scripting.FileSystemObject") Set fs = fso.OpenTextFile("c:\temp\DirSize.csv", ForAppending, True) Do WScript.StdOut.Write "Please enter directory name: " strFolder = WScript.StdIn.ReadLine If fso.FolderExists(strFolder) Then Exit Do Else WScript.StdOut.Write "Invalid Directory ... Try Again" & vbCrLf End If Loop Set f = fso.GetFolder(strFolder) WScript.Echo f.Path & ": " & GetEditSize(f.Size) fs.WriteLine f.Path & "," & Replace(GetEditSize(f.Size), " ", ",") GetThePaths(f) fs.Close Sub GetThePaths(Folder) For Each Subfolder in Folder.SubFolders WScript.Echo SubFolder.Path & ": " & GetEditSize(SubFolder.Size) fs.WriteLine SubFolder.Path & "," & Replace(GetEditSize(SubFolder.Size), " ", ",") GetThePaths Subfolder Next End Sub Function GetEditSize(intSize) If intSize => (1024*1024*1024*1024) Then GetEditSize = Round(FormatNumber((intSize/(1024*1024*1024)), 4,, TriStateTrue), 2) & " TB" ElseIf intSize => (1024*1024*1024) Then GetEditSize = Round(FormatNumber((intSize/(1024*1024*1024)), 4,, TriStateTrue), 2) & " GB" ElseIf intSize => (1024*1024) Then GetEditSize = Round(FormatNumber((intSize/(1024*1024)), 4,, TriStateTrue), 2) & " MB" ElseIf intsize => 1024 Then GetEditSize = Round(FormatNumber((intSize/1024), 4,, TriStateTrue), 2) & " KB" Else GetEditSize = intSize & " Bytes" End If End Function I'm sure we'' here from you again. Quote from: Sidewinder on July 21, 2010, 08:21:39 AM batch arithmetic only deals with integers. ... and runs out of steam at 2 G (32-bit signed integer) Hi Sidewinder, Great ! I 'm appreciate your helpful and support the code. I can get the result what I want. Are you programme ? You are specialist for vb script. Except for Microsoft link, what is other link for script which is useful for beiginner. VBscript. Batch , Shell script Thank you very much ! Quote from: sun_os on July 24, 2010, 04:06:43 AM Are you programme ? You are specialist for vb script. I'm retired now after being in IT my entire career from EAM operator to systems administrator. Currently I run a small business in the local village helping some of the small business owners with their software needs and day to day PC operations. For batch CODING I always recommend this site For VBScript check out this tutorial Also do a search on your hard drive for a file named script56.chm. This is a VBScript reference with lots of examples. Never leave home without it. If you can't find it on your hard drive, you can download it from here Good luck. I come from H.K. and work for system engineer. My employment is only for the three months CONTRACT. The IT in H.K. is no long term career, company prefer to recruit the outsource to support the inhouse I.T operation. I have a dream to start the own business but it is a lot of competitor in Hong Kong. The profit margin is not very good in Hong Kong. May I know where are you living ? Enjoy your life and retirement ! |
|