I need to move a file from one directory to another in the android filesystem. How can I programmatically check if the two paths is on the same mountpoint?
The reason I want to know this is because if they are, we need to copy the bits instead of using File.rename(newPath).
Examples when the paths is on different mountpoints:
The user wants to move a file from the internal to external storage.
The user wants to move a file from /sdcard/files to /sdcard/external_sd/files on a samsungdevice.
Call File.rename
. If it succeeds, they're on the same mountpoint.
One way to determine which filesystem a file resides on from within an Android app:
get the file's canonical path by calling File.getCanonicalPath() on it.
then get the list of currently mounted filesystems & their mount point paths from /proc/mounts
and find which mount point path is the most complete string match for the canonical path of the file in question, this should give you the mount point / filesystem of the file.
Compare results from the two files.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With