question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

copyFileTo creates subdirectory in target directory with target's name

See original GitHub issue

Hi, first let me thank you for this great library.

Library version: 1.5.1 OS version: [Android 12] Device model: Realme 7

In my app the user can choose a file (mStorageHelper.openFilePicker()), after this the selected file is copied to the apps internal storage and user can edit it in the app. After editing the user can finish editing and copy back the file to the original place. When I copy the file back from the apps storage to the original folder, the copyFile methode creates a subfolder in the target

File sourceDBFile = new File(data.m_filename);
// app internal filename data.m_filename = "/data/user/0/xxx.xxx.xxx/files/projects/yyy.db"
DocumentFile source = DocumentFile.fromFile(sourceDBFile);

DocumentFileUtils.copyFileTo(source, ctx, data.m_localImportSourcePath, null, new FileCallback() ...
// with data.m_localImportSourcePath = "/storage/emulated/0/test", this is the original folder

Result is the copied file yyy.db is in the folder /storage/emulated/0/test/test with absolute path
/storage/emulated/0/test/test/yyy.db

If I try to copy to the targets parent I get the error “CANNOT_CREATE_FILE_IN_TARGET”, of course I only have the permission for the “test” folder How can I prevent this? Is this the intented behaviour? Thx and best reagrds Klaus

Issue Analytics

  • State:closed
  • Created 10 months ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
anggrayudicommented, Nov 28, 2022

As a temporary solution, please go ahead with copyFileTo(Context, DocumentFile, FileDescription, FileCallback):

DocumentFile source = DocumentFile.fromFile(sourceDBFile);
// Parameter requiresWriteAccess must be "true", because you're going to write files into it
DocumentFile targetFolder = DocumentFileCompat.fromFullPath(this, data.m_localImportSourcePath, DocumentFileType.ANY, true);
DocumentFileUtils.copyFileTo(source, ctx, targetFolder, null, new FileCallback());
0reactions
anggrayudicommented, Dec 7, 2022

Fixed in v1.5.2

Read more comments on GitHub >

github_iconTop Results From Across the Web

NuGet package targets - how to copy files to subfolder of ...
I am able to create a targets file that copies 1.txt to the root, ... you get it to create the SubFolder and...
Read more >
Copy and Create Destination Directory if it Does Not Exist
In this tutorial, we'll discuss how to create the non-existing target directory automatically when we copy files.
Read more >
CopyFiles@2 - Copy files v2 task
Copy files v2 # Copy files from a source folder to a target folder using patterns matching file paths (not folder paths).
Read more >
Makefile for Projects with Subdirectories - Dash's Blog
The directory part of the file name of the target, with the trailing slash removed. If the value of $@ is dir/foo.o then...
Read more >
How to CMake Good - 1c - Subdirectories and Target Interface ...
You probably don't want a single flat project structure, especially if you have many files and targets. You'll also want to tag "usage ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found