Wish File.Copy - FileCopy_Completed event

LucaMs

Expert
Licensed User
Longtime User
I wrote 3 consecutive lines to copy 3 files from Assets to DirDefaultExternal.
Then I tried to send those files using FTP; for the second and third file I got a "no such file or directory found" message.

Investigating I found that second and third copy failed, without exceptions.
Adding Sleep(2000) after each copy line, the project works.

It would be "nice" to have a Copy_Completed event or, at least, an exception - error message.

(If that 2 seconds pause was not enough or was excessive?)
 

LucaMs

Expert
Licensed User
Longtime User
Are you using File.Copy2? Are you closing the output stream?
No, three simple File.Copy (Activity_Create):
B4X:
File.Copy(File.DirAssets, "FileToSend1.txt", File.DirDefaultExternal, "FileToSend1.txt")
Sleep(2000)
File.Copy(File.DirAssets, "FileToSend2.txt", File.DirDefaultExternal, "FileToSend2.txt")
Sleep(2000)
File.Copy(File.DirAssets, "FileToSend3.txt", File.DirDefaultExternal, "FileToSend3.txt")
Sleep(2000)

It was and old FTP test project, so there are only other lines releated to FTP (initialization, make dir, upload file, list file), nothing else.

The three files are almost empy text files.
 

Star-Dust

Expert
Licensed User
Longtime User
It also happened to me.
I solved that, otherwise you report error "file not found"

B4X:
File.Copy(File.DirAssets,NameFile,File.DirInternal,NameFile)
DelaySub(300)
WebView1.LoadHtml(File.ReadString(File.DirInternal,FileName))

On delay sub, i use DoEvents (deprecated) for generate a wait
 

Star-Dust

Expert
Licensed User
Longtime User
Some files gave me this mistake no more. But it does not depend on the lenght of file in my case. It's really weird.

For security, not knowing which files could generate the error I paused before on each reading
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…