Jump to content

Monitor files being written to disk in realtime?


Recommended Posts

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

 

Link to comment
Share on other sites

It's a nice UDF, but it's not working for live video recording. I still have to refresh the folder to see the changes detected. It's working with regular files though (ie writing to a text file).

I did my tests with this:

FileSystemMonitor UDF

https://www.autoitscript.com/forum/topic/148327-filesystemmonitor-udf-partially-broken-in-x64-environment-autoit-v3381/

 

Link to comment
Share on other sites

57 minutes ago, carloselectro said:

It's a nice UDF, but it's not working for live video recording

_WinAPI_ReadDirectoryChanges(), try that as is. Then play around. I use it with MailSlot UDF for IPC to another script that then works with the info.
If you find it to be the solution, please post the results here.

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...