PDA

View Full Version : Possible via vba to check the datetime stamps on files in a directory?



Salient
06-28-2012, 03:05 PM
Must admit to not having got stuck into this requirement yet so maybe should have checked the functions etc.

Basically I want to check a directory to see if a file has been written into it in the last half an hour by another process. One of those watchdog processes.

Anyways is this possible?

Paul_Hossler
06-28-2012, 03:59 PM
http://www.cpearson.com/excel/FileTimes.htm


Chip's always got a lot of useful stuff on his site

Paul

snb
06-29-2012, 12:11 AM
msgbox filedatetime("G:\OF\files.xls")

Bob Phillips
06-29-2012, 01:45 AM
It sounds as if you need a combination of a macro that looks at all of the files in a nominated directory using Dir to get each file, and OnTime to fire the macro at preset intervals.

Kenneth Hobs
06-29-2012, 10:42 AM
OnTime or a Windows Scheduled task might be methods that you could use for VBA code. The OnTime method might work for you: http://www.mrexcel.com/forum/showthread.php?528653-VBA-is-a-File-watcher-possible

For something like that, I would probably use vb.net. I gave a lesson on how to do that at: http://www.wpuniverse.com/vb/showthread.php?31419-Watch-Folder&highlight=watchfolder

If you don't want to register for free at WordPerfect Universe to see this lesson and my other vb.net lessons, explore these vb.net links on the topic:
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx
http://www.vbdotnetheaven.com/uploadfile/9972f3/filesystemwatcher-control-in-VB-Net/
http://www.codeproject.com/KB/dotnet/folderwatcher.aspx
http://www.developerfusion.com/article/3636/watching-folder-activity-in-vbnet/2/

Depending on your need, there are some ShellWait routines that can wait on a process, such as writing to a large text file, to complete before continuing on.