none
FileSystemWatcher skip read only files RRS feed

  • Question

  • Hi All, 

    Please share we have any property available for FileSystemWatcher that skips read only files. 

    Like we have for 

    IncludeSubdirectories = false;

    InternalBufferSize = 32768;

    Thanks 

    Priya

    Monday, November 18, 2019 8:53 AM

All replies

  • You need to implement that in event handlers so that if file/directory has read only attribute then ignore it.
    • Edited by MasaSam Monday, November 18, 2019 10:09 AM
    Monday, November 18, 2019 10:08 AM
  • Use Attributes member of the  NotifyFilter property

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Monday, November 18, 2019 10:28 AM
    Moderator
  • Use Attributes member of the  NotifyFilter property

    Please remember to mark the replies as answers if they help and unmarked them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.

    NuGet BaseConnectionLibrary for database connections.

    StackOverFlow
    profile for Karen Payne on Stack Exchange

    Hello,

    So, if I use 

    NotifyFilter = NotifyFilters.FileName | NotifyFilters.LastWrite |NotifyFilters.Attributes ;

    This will prevent to skip read only files or I need to set the value also of the Attribute. Please guide.

    Monday, November 18, 2019 11:09 AM
  • What you actually want? That you do not get notified if someone change read-only attribute or you do not want to be notified if someone for example access read-only file? Those are different things.

    With NotifyFilters.Attributes you inform do you like to be notified about attribute value changes. You can use it if that is what you need. If instead you want to ignore everything related to read-only files, like access, change of attributes etc. then I think only solution is to check in event handler if file has read-only attribute and if so, then ignore it.


    • Edited by MasaSam Monday, November 18, 2019 11:58 AM
    Monday, November 18, 2019 11:58 AM
  • The FSW is for monitoring changes to files. If a file is read only then why would it change and hence why would FSW kick in? The only time you'd likely get a read only file is if the file were copied into a directory (and the attributes left intact). At this point just filter out the read only files you don't care about using a simple check on the file attributes.

    Michael Taylor http://www.michaeltaylorp3.net

    Monday, November 18, 2019 2:49 PM
    Moderator