1

I have the following function:

[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern int GetLongPathName(
    [MarshalAs(UnmanagedType.LPTStr)]
    string path,
    [MarshalAs(UnmanagedType.LPTStr)]
    StringBuilder longPath,
    int longPathLength
);

This works with files and folder paths that are available on the device. But if I have a DELETED item then I get an empty string. The path of the deleted item which comes from the FilesystemWatcher looks something like this 'C:\abc\FIRSTF~1\SECOND~1\THIRDF~1\FOURTH~1\FIFTHF~1....\AVIA~1.jpg'.

Is there a way to get the long path of a deleted item?

H44R
  • 13
  • 3
  • [This question](https://stackoverflow.com/q/4179270/4137916) documents a solution, ugly as it is: cache all path components' long names so you can deal with short names. – Jeroen Mostert Sep 15 '22 at 09:28
  • Ouh. That sounds really ugly. I hoped there is an easier way. – H44R Sep 15 '22 at 12:08
  • 1
    Unlikely. A deleted file is a deleted file; it is no longer possible to get the long file name from it, since the essential information is simply no longer there in the metadata. In effect the name no longer has any meaning to the file system. – Jeroen Mostert Sep 15 '22 at 13:40

0 Answers0