Backports #34215 and 2 required commits from #31423
Note that this backport is unclean. The second commit (introduction of Files()) requires changes to list BDB files. The last commit (fix from #34215) requires test changes to deal with the test using an unnamed wallet in some places.