Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Checking the file size for a particular day

Posted on 2011-05-03
15
Medium Priority
?
317 Views
Last Modified: 2012-05-11
Hi

How can I modify the script to make the file compare in the archive folder with a particular day file only.
Set objFSO = CreateObject("Scripting.FileSystemObject")

strMainFolder = "C:\Backups"
strBackupFolder = "C:\BackupArchive"
strOutput = "Differences.csv"

Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """File Name"",""Size Difference (kb)"""
If Right(strBackupFolder, 1) <> "\" Then strBackupFolder = strBackupFolder & "\"
For Each objFile In objFSO.GetFolder(strMainFolder).Files
      If objFSO.FileExists(strBackupFolder & objFile.Name) = True Then
            objOutput.WriteLine """" & objFile.Name & """,""" & (objFile.Size - objFSO.GetFile(strBackupFolder & objFile.Name).Size) / 1024 & """"
      Else
            objOutput.WriteLine """" & objFile.Name & """,""N/A"""
      End If
Next
objOutput.Close
WScript.Echo "Done. Please see " & strOutput


Thanks

regards

rahul
0
Comment
Question by:surah79
  • 9
  • 6
15 Comments
 
LVL 12

Expert Comment

by:prashanthd
ID: 35511213
Could you give an example?
0
 

Author Comment

by:surah79
ID: 35511410
Hi prashant

In the Archive folder we have the same files for different days, so what i want to compare the files which generated today with yesterday.
Folder1 : 1.csv(generated today)
ArchiveFilder: 1.csv(generated yesterday)
So i have to compare these two files which have same name and send the size difference to another
file.

Bascially in the above i am trying to put a condition where it can only compare the files which have been generated a day before than today

regards
rahul
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35511483
Try the following..

regards
Prashanth
strMainFolder = "C:\Backups"
strBackupFolder = "C:\BackupArchive"
strOutput = "Differences.csv"

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objOutput = objFSO.CreateTextFile(strOutput, True)
objOutput.WriteLine """File Name"",""Size Difference (kb)"""
If Right(strBackupFolder, 1) <> "\" Then strBackupFolder = strBackupFolder & "\"
For Each objFile In objFSO.GetFolder(strMainFolder).Files
	
    If objFSO.FileExists(strBackupFolder & objFile.Name) = True Then
    	Set arfile= objfso.GetFile(strBackupFolder & objFile.Name)
    	dtdiff=DateDiff("d",arfile.DateCreated,Now)
    	If dtdiff <=1 Then
        	objOutput.WriteLine """" & objFile.Name & """,""" & (objFile.Size - objFSO.GetFile(strBackupFolder & objFile.Name).Size) / 1024 & """"
        End If
    Else
        objOutput.WriteLine """" & objFile.Name & """,""N/A"""
    End If
Next
objOutput.Close
WScript.Echo "Done. Please see " & strOutput

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:surah79
ID: 35511592
Hi prashant

Its not working, notshowing anything in the output
mainfolder has four file t1,t2,t3,t4 generated today
and archive folder has all the file generated on different days.
so the script should find the file size difference between today and yesterday with same file name.

and transfer that info to other file.

regards

rahul
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35511718
strMainFolder = "C:\Backups"

The above folder has todays files right?

strBackupFolder = "C:\BackupArchive"

The above folder has yesterdays files right?
0
 

Author Comment

by:surah79
ID: 35511747
yep

the output in the output file is coming as,

File Name      Size Difference (kb)
Differences.csv      N/A

0
 

Author Comment

by:surah79
ID: 35511820
Hi prashant

Do you think we need to put this loop

dtdiff=DateDiff("d",arfile.DateCreated,Now)
          If dtdiff <=1 Then

before
For Each objFile In objFSO.GetFolder(strMainFolder).Files


regards

rahul

0
 
LVL 12

Accepted Solution

by:
prashanthd earned 1500 total points
ID: 35511991
The created date or last modified date has to be checked?

There are no sub folders in C:\BackupArchive right?
0
 

Author Comment

by:surah79
ID: 35512466
there is no subfolder in C:\BackupArchive
0
 

Author Comment

by:surah79
ID: 35512512
yep
the created date and modified date also checked
0
 

Author Comment

by:surah79
ID: 35512591
there are subfolders in the main folder does that make a difference?
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35512707
are the files are in those sub folders?

If yes can you give sample dir structure?
0
 

Author Comment

by:surah79
ID: 35513089
hi prashant

yep it has 5 sub folders ,files inside them is the same files but generated in different days.
contents of the main folder
mainfolder->Folder1,BackupArchive,Folder3,Folder4,Shortcuttoanotherfolder,files
0
 
LVL 12

Expert Comment

by:prashanthd
ID: 35513416
Which sub folder are the t1,t2,t3,t4 files in?

Will the sub folder name with today's files keep changing?

0
 

Author Comment

by:surah79
ID: 35546656
hi prashant
Mainfolder has the files t1,t2,t3,t4
no files will not be changing once they a.re generated. after generation of files they will be transferred to the archive folder next day
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Script to copy or move mouse-selected collection of files plus targets referenced by shortcuts (.lnk) The purpose of this article is to help illuminate the real challenges and options available (where they may exist) for utilizing simple scriptin…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question