Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


File Count Help

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,49006
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File Count Help
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 File Count Help - 7/3/2007 6:22:23 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Hi Guys

i was trying to find a file count and size  based on date based,already i have a code for file count but am not sure how i can count based on date

Here is the code i have

**************************************
  GetFileCount

  Sub GetFileCount
      ' define variable and set the initial folder path
      Dim strFile
    datetoday = Now
    strMonth = Month(datetoday)
    strDay = Day(datetoday)
      Dim strFolderPath : strFolderPath = "C:\temp\"
      ' define variable to hold file count
      Dim intFileCount : intFileCount = 0
 
     ' create FSO
     Dim objFSO : Set objFSO = CreateObject("Scripting.FileSystemObject")
 
     ' call RecurseFolder sub to look at subfolders and file count
     RecurseFolder objFSO, strFolderPath, intFileCount
 
     ' echo output
     WScript.Echo "Total File Count For " & _
                  Chr(34) & strFolderPath & Chr(34) & _
                  " = " & intFileCount
 End Sub

 Sub RecurseFolder(objFSO, strFolderPath, intFileCount)
     ' get folder
     Dim objFolder : Set objFolder = objFSO.GetFolder(strFolderPath)
 
 '     On Error Resume Next
     ' add the file count for the current folder to intFileCount
     intFileCount = intFileCount + objFolder.Files.Count
 '     On Error GoTo 0
 
     Dim objSubFolder
     ' loop through sub folders
     For Each objSubFolder In objFolder.SubFolders
 '         On Error Resume Next
         ' have the sub call itself sending the sub folder path
         RecurseFolder objFSO, objSubFolder.Path, intFileCount
 '         On Error GoTo 0
     Next
 End Sub
 **********************************************************

i was searching this forum and found one,dm_4ever already wrote timestamp files.

any help would be appreciated.

Thanks in Advance
 
 
Post #: 1
 
 RE: File Count Help - 7/3/2007 6:35:03 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
What do you mean count by date? Count how many files were created on a specific day? How many modified on a day?

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ashok_ganeshs)
 
 
Post #: 2
 
 RE: File Count Help - 7/3/2007 6:40:23 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Count how many files were created on a specific day and size of those files.

Thanks ebgreen .

(in reply to ebgreen)
 
 
Post #: 3
 
 RE: File Count Help - 7/3/2007 6:57:31 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
There are two ways to do this that come to mind.

METHOD 1
This method is best if you want the data for all the files in a folder. Use the FileSystemObject to get a collection of all the files that you care about. Make a dictionary that will hold your data. The key for the dictionary will be a string and the value will be another dictionary. Iterate through the files. Each file will have a create date. Take just the date portion of that (it will have time as well) and see if that date already exists in the keys of your dictionary. If it does not exist, then create a temporary dictionary that has two keys "Count" and "Size". Those keys should be assigned a value of 1 and the size of the file respectively. If that date does already exist in the dictionary, simply increment the "Count" for that entry by 1 and add the size of the file to the "Size". When you get done you will have a dictionary that has data like this:

Key                        Value
6/21/06                  Count=1;Size=1234
7/1/06                    Count=3;Size=56789
1/1/01                    Count=5;Size=987654
.
.
.


METHOD 2
This method is best if you have a specific range of dates that you want the data for. Create a loop (While, Do, For, whatever) that loops through the date range one day at a time. For each date do a WMI query for instances of the CIM_Datafile class where the CreationDate equals the day that you are currentl on in the loop. This will give you a collection of CIM_DataFile class instances. The Count of the files for that day is the .Count property of the collection. To get the size, just iterate through the collection adding up all of the individual sizes.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ashok_ganeshs)
 
 
Post #: 4
 
 RE: File Count Help - 7/3/2007 7:01:29 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Thanks for your reply Ebgreen,i will start with that logic

(in reply to ebgreen)
 
 
Post #: 5
 
 RE: File Count Help - 7/3/2007 7:04:34 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Ashok,

nice to meet you again! A somewhat more simple approach:


      

Good luck!

ehvbs

< Message edited by ehvbs -- 7/3/2007 7:06:57 AM >

(in reply to ashok_ganeshs)
 
 
Post #: 6
 
 RE: File Count Help - 7/3/2007 7:09:23 AM   
  ebgreen


Posts: 4613
Score: 31
Joined: 7/12/2005
Status: offline
Oh...perhaps I misunderstood. Ehvbs' code will tell you about the files that were created today. If that is all that you need then by all means, he has the best solution. I thought that you wanted to collected the information for all of the files in a folder and categorize the counts and sizes for every day/file present.

_____________________________

"... when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick
Goog places to start:http://www.visualbasicscript.com/m_24727/tm.htm
http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 7
 
 RE: File Count Help - 7/3/2007 7:32:51 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
For anybody who needs more details:


      

< Message edited by ehvbs -- 7/3/2007 7:41:02 AM >

(in reply to ebgreen)
 
 
Post #: 8
 
 RE: File Count Help - 7/3/2007 7:54:42 AM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
The Great Ehvbs

you still remember my name

Wow ! Nice to meet you again...that code works for me (awesome and thanks a lot).

I was thinking to write WMI after getting EBgreen reply but no need after see your code here.


Thanks Ehvbs and Ebgreen.

Ashok

(in reply to ehvbs)
 
 
Post #: 9
 
 RE: File Count Help - 7/3/2007 8:31:00 AM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi Ashok,

of course I remember you! I'm glad, your problem is solved - so maybe there is
time gained to play around a bit. ebgreen's sketch of a script using a dictionary
is very interesting. So here is a third variation of the theme "counting files":


      

Anybody feels like doing it via WMI?

(in reply to ashok_ganeshs)
 
 
Post #: 10
 
 RE: File Count Help - 7/3/2007 3:14:56 PM   
  ashok_ganeshs

 

Posts: 92
Score: 0
Joined: 12/5/2006
Status: offline
Thanks  for  File count 3, i will keep file count 2 and 3 for update my knowledge.

I will try WMI part.

Thanks Again
Ashok

(in reply to ehvbs)
 
 
Post #: 11
 
 RE: File Count Help - 7/4/2007 7:27:48 AM   
  dm_4ever


Posts: 2593
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Hi ehvbs,

Some interesting use of the dictionary object there...no surprise coming from you though.  Always a pleasure to see your contributions...so many things to learn.  Well, here is my quick attempt to do the same using WMI...it is no speed demon though. FSO leaves it in the dust, but since it uses WMI it may be better for querying remote machine and of course there's always improvement of the code though WMI is generally slower than FSO when dealing with these things.

NOTE: Can only be run on WinXP or higher because of the function to convert standard time to UTC

      

For those of us here in the U.S....Happy 4th of July!!!

< Message edited by dm_4ever -- 7/4/2007 7:34:40 AM >


_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to ehvbs)
 
 
Post #: 12
 
 RE: File Count Help - 7/6/2007 11:13:14 AM   
  Fredledingue


Posts: 370
Score: 0
Joined: 5/9/2005
From:
Status: offline
Use  DateDiff("d", time1, times2) with. oFile.DateCreated.


_____________________________

Fred

(in reply to dm_4ever)
 
 
Post #: 13
 
 RE: File Count Help - 7/17/2007 3:57:09 AM   
  BIRD

 

Posts: 1
Score: 0
Joined: 7/16/2007
Status: offline
love the code and suspect it does what I would like but... I get an error when trying to run it as a .vbs file.
Error reads: C:\Scripts\VBS\GetFileCount_2.vbs(9, 76) Microsoft VBScript compilation error: Expected ')'

Newbie guidance needed
Thanks

(in reply to Fredledingue)
 
 
Post #: 14
 
 RE: File Count Help - 7/17/2007 5:00:29 AM   
  dm_4ever


Posts: 2593
Score: 46
Joined: 6/29/2006
From: Orange County, California
Status: offline
Which code are you referring to?

_____________________________

dm_4ever

My philosophy: K.I.S.S - Keep It Simple Stupid
Read Me: http://www.visualbasicscript.com/m_24727/tm.htm
Frequently Asked Stuff: http://www.visualbasicscript.com/m_47117/tm.htm

(in reply to BIRD)
 
 
Post #: 15
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> File Count Help Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts