我找不到触发方式
FileSystemMoveEvent
。
这是一个简单的代码
final uri1 = Uri.file('junk.file');
final file1 = File.fromUri(uri1).absolute;
final sub = file1.watch().listen(print);
file1.create(); // triggers FileSystemCreateEvent
file1.writeAsString('A'); // triggers FileSystemModifyEvent
final parentUri = Directory.current.uri;
file1.renameSync('${parentUri.path}junk1.file'); // triggers FileSystemDeleteEvent
// or file1.delete(); // triggers FileSystemDeleteEvent
除了移动事件之外的所有事件都可以被触发。我什至尝试重命名父目录,但没有触发移动事件。
那么,是什么触发了
FileSystemMoveEvent
?
API链接:
可以通过监听目录的更改来触发
move
事件:
import 'dart:io';
void main() async {
final uri = Uri.file('test.file');
final file = File.fromUri(uri).absolute;
final directory = Directory.current;
final steamSubscription = directory.watch().listen(print);
await file.create(); // triggers FileSystemCreateEvent
// await file.writeAsString('A'); // triggers FileSystemModifyEvent
final processResult = await Process.run(
'mv',
['test.file', 'test_bak.file'],
workingDirectory: directory.path,
);
steamSubscription.asFuture();
steamSubscription.cancel();
print('Exiting: ${processResult.exitCode}');
}
控制台输出:
$ dart main.dart
FileSystemCreateEvent('/home/dan/stackoverflow/example/test.file', isDirectory=false)
FileSystemMoveEvent('/home/dan/stackoverflow/example/test.file', isDirectory=false,
destination=/home/dan/stackoverflow/example/test_bak.file)
Exiting: 0