 




<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>The VBScript Network and Systems Administrator&#039;s Cafe &#187; file access</title>
	<atom:link href="http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/tag/file-access/feed/" rel="self" type="application/rss+xml" />
	<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator</link>
	<description></description>
	<lastBuildDate>Tue, 11 Oct 2011 18:36:53 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
		<item>
		<title>Using the VBScript datediff function to determine the age of a file by the last modified and the last accessed time</title>
		<link>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-vbscript-datediff-function-to-determine-the-age-of-a-file-by-the-last-modified-and-the-last-accessed-time/</link>
		<comments>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-vbscript-datediff-function-to-determine-the-age-of-a-file-by-the-last-modified-and-the-last-accessed-time/#comments</comments>
		<pubDate>Sat, 02 May 2009 18:19:29 +0000</pubDate>
		<dc:creator>Jerry Lees</dc:creator>
				<category><![CDATA[Disk space]]></category>
		<category><![CDATA[disk utilities]]></category>
		<category><![CDATA[file access]]></category>
		<category><![CDATA[file modified]]></category>
		<category><![CDATA[modification date]]></category>
		<category><![CDATA[System Administration]]></category>
		<category><![CDATA[VBScipt]]></category>
		<category><![CDATA[VBScript Functions]]></category>

		<guid isPermaLink="false">http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/?p=245</guid>
		<description><![CDATA[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&#8217;re out of space on a server and can&#8217;t just add more space to it. What do you delete??? The Old files are the obvious answer&#8230; except if people are using them. Here [...]]]></description>
				<content:encoded><![CDATA[<p>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&#8217;re out of space on a server and can&#8217;t just add more space to it. What do you delete??? The Old files are the obvious answer&#8230; except if people are using them.</p>
<p>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.</p>
<p>Enjoy!</p>
<p><span style="color: #0000ff">Option Explicit</span></p>
<p><span style="color: #0000ff">Dim fName<br />
Const DateLastModified = 1, DateLastAccessed = 2</span></p>
<p><span style="color: #0000ff">fName=&#8221;c:\temp2.txt&#8221;</span></p>
<p><span style="color: #0000ff">if FileAge(fname,5,DateLastAccessed) = True Then<br />
WScript.Echo (&#8220;The file was accessed recently enough!&#8221;)<br />
Else<br />
WScript.Echo (&#8220;The file was not accessed recently enough!&#8221;)<br />
End If</span></p>
<p><span style="color: #0000ff">if FileAge(fname,5,DateLastModified) = True Then<br />
WScript.Echo (&#8220;The file was modified recently!&#8221;)<br />
Else<br />
WScript.Echo (&#8220;The file was not modified recently!&#8221;)<br />
End If</span></p>
<p><span style="color: #0000ff">Function FileAge(fName,fAge, CompareType)<br />
&#8216;function returns True if the file is older than the fAge (File Age) specified and false if it isn&#8217;t<br />
Dim LastModified, LastAccessed, FSO, DateDifference</span></p>
<p><span style="color: #0000ff"> Set FSO = CreateObject(&#8220;Scripting.FileSystemObject&#8221;)<br />
LastModified = FSO.GetFile(fname).DateLastModified<br />
LastAccessed = FSO.GetFile(fname).DateLastAccessed</span></p>
<div><span style="color: #0000ff"> Select Case CompareType<br />
Case 1<br />
DateDifference = DateDiff(&#8220;n&#8221;,LastModified, Now())<br />
Case 2<br />
DateDifference = DateDiff(&#8220;n&#8221;,LastAccessed, Now())</p>
<div><span style="color: #0000ff"> End Select<br />
If DateDifference &gt; fage Then<br />
FileAge = False<br />
Else<br />
FileAge = True<br />
End If<br />
End Function</span></div>
<p></span></div>
<div><span style="color: #0000ff"><span style="color: #0000ff"> </span></span></div>
<div><span style="color: #0000ff"><span style="color: #0000ff"> </span></span></div>
<div><span style="color: #0000ff"><span style="color: #0000ff"> </span></span></div>
<p><span style="color: #0000ff"><span style="color: #0000ff"> </span></span></p>
<!-- wpms-network-global-inserts -->]]></content:encoded>
			<wfw:commentRss>http://itknowledgeexchange.techtarget.com/vbscript-systems-administrator/using-the-vbscript-datediff-function-to-determine-the-age-of-a-file-by-the-last-modified-and-the-last-accessed-time/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
