May 2 2009 6:19PM GMT
Posted by: Jerry Lees
VBScipt,
VBScript Functions,
file access,
file modified,
modification date,
System Administration,
Disk space,
disk utilities
I recently needed a way to tell if a file had been accessed or modified recently, something that has always been a question when you’re out of space on a server and can’t just add more space to it. What do you delete??? The Old files are the obvious answer… except if people are using them.
Here is teh script I wrote to tell if a file had been accessed or modified in the last X days. In the example I use 5 days, but you can use a different number of days when you call the function.
Enjoy!
Option Explicit
Dim fName
Const DateLastModified = 1, DateLastAccessed = 2
fName=”c:\temp2.txt”
if FileAge(fname,5,DateLastAccessed) = True Then
WScript.Echo (”The file was accessed recently enough!”)
Else
WScript.Echo (”The file was not accessed recently enough!”)
End If
if FileAge(fname,5,DateLastModified) = True Then
WScript.Echo (”The file was modified recently!”)
Else
WScript.Echo (”The file was not modified recently!”)
End If
Function FileAge(fName,fAge, CompareType)
‘function returns True if the file is older than the fAge (File Age) specified and false if it isn’t
Dim LastModified, LastAccessed, FSO, DateDifference
Set FSO = CreateObject(”Scripting.FileSystemObject”)
LastModified = FSO.GetFile(fname).DateLastModified
LastAccessed = FSO.GetFile(fname).DateLastAccessed
Select Case CompareType
Case 1
DateDifference = DateDiff(”n”,LastModified, Now())
Case 2
DateDifference = DateDiff(”n”,LastAccessed, Now())
End Select
If DateDifference > fage Then
FileAge = False
Else
FileAge = True
End If
End Function
Aug 18 2008 5:48PM GMT
Posted by: Jerry Lees
free software,
Disk space,
drive space,
Systems administrator tools,
essential tools,
windows tools,
diskspace,
drivespace,
spacemonger
The next essential tool is one that I have used for quite some time now, and one I searched to find for some time. As a systems administrator, its an ever ending battle for you to keep space clear on the servers. It’s a battle that puts you smack in the middle of the users who are using all the space and the management who refuses to buy more space. Additionally, management all to often refuses to place a mandate on how old data is before it is free to delete.
This tool won’t help you delete files, but it will tell you really quickly where exactly the space is being used for any particular volume… even if it is a UNC path on your network mapped to a network drive!
This tool, spacemonger, is a tool that will show you this in a visual representation by size where space is being used. It allows you to drill down into directories to see more detail and gives you shortcuts via a context menu to common tasks you would preform on a directory.
SpaceMonger truly is an essential tool. The 1.x version I’ve linked to is older, but free and it gets the job done. Additionally, a newer version is available that has more features and is relatively cheap. Go ahead, check it out… I’m sure you’ll add it to your essential tools!
Know of a tool that you think is essential? Post a comment here and if I don’t already have it in my tool belt, I’ll add it and give it a shot. If it makes the grade– I’ll add it to the list of tools to review. The only criteria are:
- The tool must be free, or inexpensive with a “Per User” or “site” type license. (No pay per installation licenses, please)
- The tool (or it’s installation file) must be small enough to fit on a 256Mb flash drive for portability.
- Command line run time options are beneficial, but not required.
- If it has ads… it needs be truly INVALUABLE.
- It should make the user’s job easier by gathering information or preforming a task that a typical Network or Systems Administrator would preform.
Enjoy!