How to read files with spaces using Expo FileSystem

I can't find anything in the documentation but it seems that Expo's FileSystem has trouble reading files with spaces in their names.

Let's say I have two files, const file_a = 'File_A.txt' and const file_b = 'File B.txt', (note the latter has a space in the name); both have been added to my app's cacheDirectory using

import * as FileSystem from 'expo-file-system';
import * as DocumentPicker from 'expo-document-picker';
const file = await DocumentPicker.getDocumentAsync();

I then run:

const targetPath = FileSystem.cacheDirectory;

console.log(await FileSystem.getInfoAsync(targetPath + file_a));
console.log(await FileSystem.getInfoAsync(targetPath + file_b));

The output for file_a gives the appropriate information about the file. For file_b I get an error: [Unhandled promise rejection: Error: File 'file:/var/mobile/Containers/Data/Application/.../File%20B.txt -- file:///' isn't readable.]

I also get errors when trying to use the FileSystem.moveAsync() function on file_b, telling me I didn't provide a 'from' field (probably because the from field has spaces in it)

If I rename file_b to File_B.txt then reimport it, the getInfoAsync() function returns the correct information.

Is there a way to get FileSystem to work with files with spaces in their names or is there a way to simply rename the files? Of course I can't rename them via moveAsync() as the move function doesn't work, as described above.



Comments

Popular posts from this blog

Today Walkin 14th-Sept

Spring Elasticsearch Operations

Hibernate Search - Elasticsearch with JSON manipulation