Description
Description
As per the documentation https://docs.microsoft.com/en-us/dotnet/api/system.io.filesystemeventargs.fullpath?view=net-6.0 the FullPath
property should return a fully qualified path. However it appears the constructor for FileSystemEventArgs
assumes the directory passed in is fully qualified: https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemEventArgs.cs#L22
When used in conjunction with FileSystemWatcher it is possible for the path to be relative: https://github.com/dotnet/runtime/blob/main/src/libraries/System.IO.FileSystem.Watcher/src/System/IO/FileSystemWatcher.cs#L260
Reproduction Steps
Repro code:
using System;
using System.IO;
namespace MyNamespace
{
class Program
{
static void Main()
{
using var watcher = new FileSystemWatcher(@"bar");
watcher.NotifyFilter = NotifyFilters.LastWrite;
watcher.Changed += OnChanged;
watcher.Filter = "*.txt";
watcher.IncludeSubdirectories = false;
watcher.EnableRaisingEvents = true;
Console.WriteLine("Press enter to exit.");
Console.ReadLine();
}
private static void OnChanged(object sender, FileSystemEventArgs e)
{
if (e.ChangeType != WatcherChangeTypes.Changed)
{
return;
}
Console.WriteLine($"Changed: {e.FullPath}");
}
}
}
-
I created the following dir structure on my machine:
C:\foo\bar\footest.txt
-
Set the working directory to be
C:\foo
-
Run the program and then modify
footest.txt
to trigger a changed event.
Expected behavior
Output should be:
Changed: C:\foo\bar\footest.txt
Actual behavior
Current output:
Changed: bar\footest.txt
Regression?
No response
Known Workarounds
Using Path.GetFullPath
to fetch the fully qualified path
Console.WriteLine($"Changed: {Path.GetFullPath(e.FullPath)}");
Configuration
.Net 6.0
Windows 10 x64
After looking at the source I believe that this is not unique to Windows
Other information
No response