Der schöne Günther 316 Posted June 27, 2019 NTFS allows files to be compressed. When a directory is compressed, that just means its files automatically inherit the "compressed" attribute. You can use WinApi.Windows.GetCompressedFileSize(..) to find about how many bytes a file actually uses on disk. When compressed, it is less than the actual file content.# My "problem": When a file is written into a directory with the "compressed" attribute set, it will first get written without compression, then Windows will take care of compression in the background. While I query the "true" file size with GetCompressedFileSize(..), I can see it shrinking. I would like to find out when the compression has finished. Is it possible? In case someone wants to test a running Demo, here is the source for a console application: https://gist.github.com/JensMertelmeyer/eb238ce57f8bb6cbb1ef3514c3d58ae8 Share this post Link to post
PeterBelow 238 Posted June 28, 2019 Well, if you call GetCompressedFilesize repeatedly and the returned size does not change for a certain time anymore the compression is finished. . Since the compression runs in a different process (service) completely separate from yours I see no way to get informed directly. There is ReadDirectoryChangesW, which allows you to monitor the folder for changes in a file size, but that would probably have the same problem you are having now: you don't know if the change notification is the last one you will get for the file. Share this post Link to post
f.m 8 Posted July 30, 2019 (edited) Using the code in the link below it is possible to observe that during compression or decompression, the file is locked by one of the following processes: 'explorer' (if compression or decompression is started automatically), 'compact' (if compression or decompression is started using the compact.exe command). When the compression or decompression is finished, the process lock ('explorer' or 'compact') is removed. Note: the code is in c#. http://csharphelper.com/blog/2017/01/see-processes-file-locked-c/ Edited July 30, 2019 by f.m Share this post Link to post
Der schöne Günther 316 Posted July 31, 2019 Thanks, I will try that. I didn't notice the file was supposed to be locked, I think it could still be moved around in explorer while compression was taking place but I might be wrong. Share this post Link to post