# How can I detect VFS delete events from copy/paste for overwrite?

**URL:** <https://platform.jetbrains.com/t/how-can-i-detect-vfs-delete-events-from-copy-paste-for-overwrite/4806>\
**Category:** IntelliJ Platform\
**Created:** [August 6, 2026, 5:22pm UTC](https://platform.jetbrains.com/t/how-can-i-detect-vfs-delete-events-from-copy-paste-for-overwrite/4806 "2026-08-06T17:22:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![illuminatedcloud](https://sea1.discourse-cdn.com/flex001/user_avatar/platform.jetbrains.com/illuminatedcloud/32/55_2.png) [@illuminatedcloud](https://platform.jetbrains.com/u/illuminatedcloud)\
**Post date:** [August 6, 2026, 5:22pm UTC](https://platform.jetbrains.com/t/how-can-i-detect-vfs-delete-events-from-copy-paste-for-overwrite/4806/1 "2026-08-06T17:22:47Z")

</div>

My plugin has a `VirtualFileManager.VFS_CHANGES` listener that performs various post-processing tasks when source files change in certain ways. It has some specific behavior when source files are deleted.

One of my users logged a bug where using the IDE’s file copy/paste-for-overwrite functionality is triggering that delete logic incorrectly given that it’s effectively a contents change event. This is because `CopyFilesOrDirectoriesHandler.handleExistingFiles()` actually deletes the existing file before copying the new file:

```java
ThrowableRunnable<RuntimeException> doCopy = () -> {
  if (progressIndicator != null) {
    progressIndicator.setText2(InspectionsBundle.message("processing.progress.text", existing.getName()));
  }
  existing.delete();
  ((PsiDirectoryImpl)targetDirectory).executeWithUpdatingAddedFilesDisabled(() -> ContainerUtil.addIfNotNull(added, tDirectory.copyFileFrom(name, replacement)));
};

```

Is there a good way to detect that a VFS delete is occurring in this context so that it can be safely ignored or handled differently? I already have event filtering for things like `VirtualFileEvent.isFromRefresh()` and `UndoManager.isUndoInProgress()`. I’m hoping that there’s something similar for this specific instance of virtual file removal.
