Tjitte,
What agraham is saying is that if "File.DirRootexternal" works in one spot in your app while using targetSdkVersion="30", then it should work in other spots of your app as well. So, if is does work in one spot, but fails in another spot, then that just means the problem is NOT with File.DirRootexternal.
So, there is something else going on that is preventing File.DirRootexternal from working in that other spot.
So, you basically need to do trial and error to make your app smaller and smaller until it starts to work in both spots, then you should discover what you last changed that allowed it to work.