简体   繁体   中英

Java7 WatchService: Is there a “built-in” way to Ignore OS-specific files like .DS_Store?

So, I know it's somewhat possible "the manual way" to do ignore such files.

At the Moment, I do it like:

Path filename = ev.context();

if(filename.equals(".DS_Store")){
  break; //the event loop
}

But this seems a little hacky for me (ok, I could create an enum for the string, create a method which checks and so on, but still, in the context of os-specific generated files I hoped to find something "built-in" to handle this for me.), so I'm asking you if there's some kind of built-in way in Java7 WatchService I haven't discovered yet to ignore such files.

ps: For my use-case it's (sadly) not an option to do it the other way round, like "ignore all files except pattern ". It has to be "Allow all files except a very few ones".

I don't believe Java supports an OS-specific file name check. However, it seems fine to check for hidden files, but I would prefer the more general starts with '.'

if (filename.charAt(0) == '.') {
  continue; // skip hidden files. break is probably wrong, I'd continue.
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM