user1801387
user1801387

Reputation:

vb.net sequential file access

I'm working on finding a way to monitor a folder's files.

I want to get information on what files are used the most in a folder.

I've looked into using vb.net FileSystemWatcher but it doesn't seem to contain any classes for this. The articles I've found don't mention anything functions like this. I found one forum that said to use the timestamp from LastAccess in FileSystemWatcher. But the description doesn't really match that function.

Is there a way in vb.net to do this?

Upvotes: 1

Views: 246

Answers (1)

sloth
sloth

Reputation: 101122

The FileSystemWatcher is indeed the class you want to use.

The msdn documentation contains an example of how to use it.

Just ensure you are setting the NotifyFilter to use the LastAccess filter:

watcher.NotifyFilter = NotifyFilters.LastAccess

This way you could create an application or service that monitors your folder and count how often each file is accessed.


But to have this work, you have to have the Last Access Time functionality enabled. By default, this is disabled on Windows Vista and up.

You can enable/disable this by either using this registry key

HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\FileSystem\NtfsDisableLastAccessUpdate

or by simply running

fsutil behavior set disablelastaccess 0

from a command prompt with administrator rights.

Upvotes: 1

Related Questions