carloselectro

Monitor files being written to disk in realtime?

7 posts in this topic

#1 ·  Posted

Hi,

I'm trying to check continuously if an application is writing to a specific folder. I was thinking of doing it like the example below but I have to manually refresh the folder in windows otherwise Autoit will always get the same folder size. The application is recording videos in MP4.

If there is a fast way of checking if the application is recording a file I'm willing to change my code.

 

$Record_Folder = "C:\Videos\"

While (1)
    $foldersize_1 = DirGetSize($Record_Folder)
    ConsoleWrite("Folder size now : " & $foldersize_1 & @CRLF)
    Sleep(2000)
    $foldersize_2 = DirGetSize($Record_Folder)
    ConsoleWrite("Foldersize after 2 seconds : " & $foldersize_2 & @CRLF)
WEnd

 

Share this post


Link to post
Share on other sites



#4 ·  Posted

Share this post


Link to post
Share on other sites

#5 ·  Posted

Same problem, it detects a couple of writes when I start recording and stops detecting anything after 3 or 4 seconds.

Here"s my code:

#include <APIFilesConstants.au3>
#include <Array.au3>
#include <MsgBoxConstants.au3>
#include <WinAPIDiag.au3>
#include <WinAPIFiles.au3>
#include <WinAPISys.au3>


Global $g_sPath = "C:\Videos"


Local $hDirectory = _WinAPI_CreateFileEx($g_sPath, $OPEN_EXISTING, $FILE_LIST_DIRECTORY, BitOR($FILE_SHARE_READ, $FILE_SHARE_WRITE), $FILE_FLAG_BACKUP_SEMANTICS)

If @error Then
    _WinAPI_ShowLastError('', 1)
EndIf

Local $pBuffer = _WinAPI_CreateBuffer(8388608)

Local $aData
While 1

    $aData = _WinAPI_ReadDirectoryChanges($hDirectory, BitOR($FILE_NOTIFY_CHANGE_LAST_WRITE, $FILE_NOTIFY_CHANGE_SIZE,$FILE_NOTIFY_CHANGE_LAST_ACCESS), $pBuffer, 8388608, 0)
    If Not @error Then
        ConsoleWrite("Writting" & @CRLF)

    Else
        _WinAPI_ShowLastError('', 1)
    EndIf
    Sleep(200)
WEnd

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

14 minutes ago, carloselectro said:

Same problem, it detects a couple of writes when I start recording and stops detecting

ok, ... the sleep is undesired, use a ToolTip(@sec&@MSEC) to see the event triggering.
What is needed is the fastest return to be ready for the next event. Now, I've tried this code writing 40000 ( yes, 40 thousand ) files to a ram disk, at a rate of 2 files per millisecond and captured every event of addition and modification, so I know the code is fine.
There is another issue here and that is that the file is opened by the application,  streaming along and does not tell the OS, but I'm sure that once it's done writing, it closes the file and the OS picks it up and your code reflects the event, in this case, modified. The other thing you can do to try to determine if the drive is too full is to use DriveSpaceFree() or DriveSpaceTotal(). Try that, it may be a solution, for I believe the problem is drive space.

Edited by argumentum

Share this post


Link to post
Share on other sites

#7 ·  Posted

32 minutes ago, argumentum said:

There is another issue here and that is that the file is opened by the application,  streaming along and does not tell the OS,  

 

I bet it's the problem too.

 

33 minutes ago, argumentum said:

The other thing you can do to try to determine if the drive is too full is to use DriveSpaceFree() or DriveSpaceTotal(). Try that, it may be a solution, for I believe the problem is drive space.

 

The DriveSpaceFree() function seems to be working for what I need to do, I can now see disk space decreasing as opposed to The DirGetSize() function that would not work.

Thanks a lot for your help

1 person likes this

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now