Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with vbscript

Status
Not open for further replies.

GavinRoss

MIS
Joined
Aug 31, 2011
Messages
8
Location
US
Hello,

I am using the below script to look for files on a server that are older than a specific time and then move them to a new location. The question I have is... how can I display how much space each one of the files is taking up?

Dim objFSO, ofolder, objStream

Set objShell = CreateObject("WScript.Shell")
Set objFSO = CreateObject("scripting.filesystemobject")
Set objNet = CreateObject("WScript.NetWork")
Set FSO = CreateObject("Scripting.FileSystemObject")
set outfile = fso.createtextfile("Move-Result.txt",true)
SPath = "C:\Excel"

ShowSubFolders FSO.GetFolder(spath)

Sub ShowSubFolders(Folder)
For Each Subfolder in Folder.SubFolders
CheckFolder(subfolder)
ShowSubFolders Subfolder
Next
End Sub

CheckFolder(objFSO.getFolder(SPath))

Sub CheckFolder(objCurrentFolder)
Dim strTempL, strTempR, strSearchL, strSearchR, objNewFolder, objFile
Const OverwriteExisting = TRUE
currDate = Date
dtmDate = Date - 180
strTargetDate = ConvDate(dtmDate)
For Each objFile In objCurrentFolder.Files
FileName = objFile
WScript.Echo FileName
strDate = ConvDate(objFile.DateCreated)
strDate = ConvDate(objFile.DateLastModified)
If strDate < strTargetDate Then
'objFSO.MoveFile FileName, "C:\test\"
outfile.writeline filename
End If
Next
End Sub

Function ConvDate (sDate) 'Converts MM/DD/YYYY HH:MM:SS to string YYYYMMDD
strModifyDay = day(sDate)
If len(strModifyDay) < 2 Then
strModifyDay = "0" & strModifyDay
End If
strModifyMonth = Month(sDate)
If len(strModifyMonth) < 2 Then
strModifyMonth = "0" & strModifyMonth
End If
strModifyYear = Year(sDate)
ConvDate = strModifyYear & strModifyMonth & strModifyDay
End Function

Thanks
 
objFile.Size will give you the size of the file in bytes.
 
dig a little deeper into the objFSO object model. I believe you'll find the size in there...

Hope this helps

Ernest

Be Alert, America needs more lerts
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top