When is the filesystem ready?
When is the filesystem ready?
On Windows, when copying or moving files to a folder (from outside PureBasic), I need to know when there's no file activity going on inside it. So like if I do a file copy on large file in Explorer with Ctrl+C (source) and Ctrl+V (paste), I want my app to know when it's complete. How can I do that? I can't check with FileSize() because it's not done from PureBasic, and also, when the copy is done, it takes a moment for the file to actually appear in the folder.
Re: When is the filesystem ready?
Hi ebs, unfortunately those monitoring tips can't help because when a large file is added, I get the trigger about it being added but the file is nowhere near finished copying, as shown below. That's my problem. I need to know when the file is finished copying, and for multiple files, so that there is no more file activity of any kind in the folder. Thanks anyway for the idea!
Re: When is the filesystem ready?
I had solved a similar problem using ts-soft CopyDirEx - Module
With it, FileSize remains available and thus, my progress bar continues to advance while copying large files.
With it, FileSize remains available and thus, my progress bar continues to advance while copying large files.
Re: When is the filesystem ready?
Thanks, but PureBasic is not copying the files (see my first post).
Re: When is the filesystem ready?
Maybe you could try to open the file to know if it's locked by Windows?
Re: When is the filesystem ready?
Can't do that, because some folders have thousands of files to open/check, such as my MP3 folder. Can't check the lock on all those just to see if any new file activity is going on in there.
Re: When is the filesystem ready?
Maybe Sync can help?
Re: When is the filesystem ready?
I'll check out Sync more closely tomorrow, but it needs admin rights to run (limits its use) and Win 10 also gave an alert that it stopped it modifying memory, which was scary to see. Not sure I want to depend on a third-party tool, either (its EULA prevents commercial use). Thanks for suggesting it, though!
Re: When is the filesystem ready?
There will always be an open handle to the file while it is being written, so you can detect this by enumeration of handles (NtQueryProcessInformation)
Re: When is the filesystem ready?
Can't check individual file handles, as I said. There could be thousands of them. And if one file is huge (like my example above), then I'd have to keep polling its handle at regular intervals before moving onto the next file. This approach is totally inefficient.
There doesn't seem to be a simple "this dir has activity" API check, so I guess it's a lost cause.
There doesn't seem to be a simple "this dir has activity" API check, so I guess it's a lost cause.
Re: When is the filesystem ready?
The original question still has different solutions - depending on what exactly you want to know. But i still think sync is the answer. Peek into the sync source and you will see the windows api call you look for. Or just use runprogram and call sync.
Re: When is the filesystem ready?
see https://docs.microsoft.com/en-us/window ... ificationsThere doesn't seem to be a simple "this dir has activity" API check, so I guess it's a lost cause.
An application can specify a set of conditions that trigger a change notification by using the FindFirstChangeNotification API function (and then FindNextChangeNotification in a loop). The conditions include changes to file names, directory names, attributes, file size, time of last write, and security.
To retrieve information about the specific change as part of the notification, use the ReadDirectoryChangesW function. This function also enables you to provide a completion routine.
(you'll probably want to call them from inside another thread, as FindFirstChangeNotification is a blocking function - it will hang your thread until a notification event is triggered, and while it's likely it will happen fairly quickly there is no actual guarantee that it will ever happen)
Some PB examples to help get you started:
https://www.purebasic.fr/english/viewtopic.php?t=14776
viewtopic.php?f=5&t=74611
https://www.cyberforum.ru/pure-basic/thread1520399.html