I will move certain files. how to move the image file from directory to another directory, example file img.jpg from /storage/emulated/0/Myfolder to /storage/emulated/0/Urfolder?
0" Then follow the steps: Run flutter upgrade in the terminal to upgrade Flutter Run dart migrate to run the dart migration tool. Solve all errors which the migration tool shows. Run flutter pub outdated --mode=null.
You can move a file or folder from one folder to another by dragging it from its current location and dropping it into the destination folder, just as you would with a file on your desktop. Folder Tree: Right-click the file or folder you want, and from the menu that displays click Move or Copy.
To move files, use the mv command (man mv), which is similar to the cp command, except that with mv the file is physically moved from one place to another, instead of being duplicated, as with cp.
await File('/storage/emulated/0/Myfolder').rename('/storage/emulated/0/Urfolder')
If the files are on different file systems you need to create a new destination file, read the source file and write the content into the destination file, then delete the source file.
File.rename
works only if source file and destination path are on the same file system, otherwise you will get a FileSystemException
(OS Error: Cross-device link, errno = 18). Therefore it should be used for moving a file only if you are sure that the source file and the destination path are on the same file system.
For example when trying to move a file under the folder /storage/emulated/0/Android/data/ to a new path under the folder /data/user/0/com.my.app/cache/ will fail to FileSystemException
.
Here is a small utility function for moving a file safely:
Future<File> moveFile(File sourceFile, String newPath) async {
try {
// prefer using rename as it is probably faster
return await sourceFile.rename(newPath);
} on FileSystemException catch (e) {
// if rename fails, copy the source file and then delete it
final newFile = await sourceFile.copy(newPath);
await sourceFile.delete();
return newFile;
}
}
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