0

In our client application implemented in C# with .Net framework 4.8 (OS: Windows 10), we are using file system watcher control to detect folder's events.

To support a long path we have tried with \\?\ in folder path. When we create a new file in long path, file system watcher detects "Created" event and it returns correct format of full path. However when we delete the file from long path, watcher control's "Deleted" event fires but it returns the full path having ~ tilde in folder's names and in file name. e.g \\?\C:\abc\FIRSTF~1\SECOND~1\THIRDF~1\FOURTH~1\FIFTHF~1\....\AVIA~1.jpg

We have tried below win32 method to get correct full path, however its not returning full path,

[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)]
private static extern Int32 GetLongPathName(String shortPath, StringBuilder longPath, Int32 longPathLength);

Can anybody please suggest is there any upgrade version of file system watcher control to support long path or any other alternatives to get correct long path on file's delete or rename event?

James Z
  • 12,209
  • 10
  • 24
  • 44
James
  • 3
  • 3
  • try `Path.GetFullPath(@"the ~ path")` – Lei Yang Feb 21 '22 at 15:28
  • Check in `HKLM\SYSTEM\CurrentControlSet\Control\FileSystem` that the feature is enabled (`LongPathsEnabled=1`) and add `true` in app.manifest, in `\`, which should have the form ``. GetLongPathNameW should work. – Jimi Feb 21 '22 at 15:34
  • I would try to add a hard link to the folder in surveillance to shorten the path for 2 reasons: 1st FileSystemWatcher has less buffer overflows, if the file paths and names are shorter, 2nd test, whether this works with hard link paths too. Or if it won't work, use short folder names and make hard links with longer folder names. – BitLauncher Feb 21 '22 at 17:45

0 Answers0