What i want to do?
I want to delete a File using the expo-file-system
package as my way to manipulate the File System of my Samsung Phone.
How i am actually doing it?
I am using this Code:
import * as EFS from "expo-file-system";
class ExternalFileSystemAdapterClient {
constructor () {}
public async deleteFile({ SAFPath, fileName }) {
const pathToFile = SAFPath + fileName;
logger.log(logName + " Deleting File: " + (pathToFile))
await EFS.StorageAccessFramework.deleteAsync(pathToFile)
.then(logger.log(logName + " File successfully deleted!"))
.catch((e) => logger.error(logName + e));
}
}
I call it with this:
import ExternalFileSystemAdapterClient from "./components/functions/file-system/external-file-system";
const efs = new ExternalFileSystemAdapterClient ()
// Delete File
try {
logger.log(
await efs.deleteFile({
SAFPath: "content://com.android.externalstorage.documents/tree/primary%3ATest/",
fileName: "Peter.txt",
})
);
} catch (error) {
logger.warn(logName + error);
}
Console Output:
"PermissionState": {"directoryUri": "content://com.android.externalstorage.documents/tree/primary%3ATest", "granted": true}
ExternalFileSystemAdapter: Deleting File: content://com.android.externalstorage.documents/tree/primary%3ATest/Peter.txt
ExternalFileSystemAdapter: File successfully deleted!
Whats the Problem?
Actually the Problem is that not the File gets deleted, as i would expect, but its deleting the Folder recursively – while the API Documentation says that there will be the file deleted, if provided…
maybe i messed something up?