public testFileSystemWatcher(): Disposable {
// const pathFileExt = 'C:\\VST\\test_fileSystemWatcher.txt';
// const pathFileExt = '**/txt';
// const pathFileExt = '**/*.txt';
const pathFileExt = '**\\*.txt';
// const pathFileExt = 'C:\\VST\\test_fileSystemWatcher.txt';
// const pathFileExt = 'C:\\VS\\VscExtensionSqlTemplateInjector\\src\\SqlTemplateGuidUtils.ts'
// const pathFileExt = 'C:/VS/VscExtensionSqlTemplateInjector/src/SqlTemplateGuidUtils.ts'
// const pathFileExt = '/src/SqlTemplateGuidUtils.ts'
// const pathFileExt = '**/*.ts'
// const pathFileExt = '**//*.ts'
// const pathFileExt = '**\*.ts'
// const pathFileExt = '**\\*.ts'
const fileSystemWatcher: FileSystemWatcher = workspace.createFileSystemWatcher(pathFileExt);
window.showInformationMessage(`Watching ${pathFileExt}`);
fileSystemWatcher.onDidCreate(_ => {
console.log(`Created ${_.fsPath}`);
});
fileSystemWatcher.onDidChange(_ => {
console.log(`Changed ${_.fsPath}`);
});
fileSystemWatcher.onDidDelete(_ => {
console.log(`Deleted ${_.fsPath}`);
fileSystemWatcher.dispose();
});
return fileSystemWatcher;
}
class Program {
static FileSystemWatcher fsw;
static void Main(string[] args) {
//fsw = new FileSystemWatcher(@"C:\VST\", "test_fileSystemWatcher.txt");
fsw = new FileSystemWatcher(@"C:\VST\", "*.txt");
fsw.EnableRaisingEvents = true;
Console.WriteLine($"Watching path {fsw.Path} filter {fsw.Filter}");
fsw.Changed += (s, e) => Console.WriteLine("File changed");
fsw.Created += (s, e) => Console.WriteLine("File created");
fsw.Deleted += (s, e) => {
Console.WriteLine("File deleted");
fsw.Dispose();
};
Console.WriteLine("Press any key to terminate application");
Console.ReadKey();
}
}
In my case I would like to detect changes to a file on a path different from the VS Code workspace. However, I haven't been able to get it to detect changes to files on any path.
I wonder if there might be something else going on here such as a permissions issue. But that seems unlikely since running VS Code under an machine-Admin account doesn't resolve it either.