Android Question File.copy, copy is bigger than original...

MitchBu

Active Member
Licensed User
I want to log PDF files used to print, so I did this after creating 1.pdf :

B4X:
    If File.Exists(File.DirInternal, "1.pdf") = True Then
        File.Copy(File.DirInternal,"1.pdf",File.DirDefaultExternal,"Print-" & DateTime.Now & ".pdf")
End If
Original (1.pdf) is 21.91 KB
Copy (Print-1560764371069.pdf) is 39.13 KB

Both seem to be valid pdf documents.

Is there any reason to that size difference ?
 

Erel

Administrator
Staff member
Licensed User
It is a mistake to use File.DirDefaultExternal. See the runtime permissions video tutorial.

What is the output of:
B4X:
Log(File.Size(File.DirInternal, "1.pdf"))
Log(File.Size(File.DirDefaultExternal,"Print-" & DateTime.Now & ".pdf"))
 

MitchBu

Active Member
Licensed User
OK. Now I have

B4X:
If File.Exists(File.DirInternal, "1.pdf") = True Then
        Dim f As String = rp.GetSafeDirDefaultExternal("")
        Log("safedir: " & f)
        File.Copy(File.DirInternal,"1.pdf",F,"Printo-" & DateTime.Now & ".pdf")
But yet, the copy remains much bigger than the original.
 

MitchBu

Active Member
Licensed User
B4X:
Log(File.Size(File.DirDefaultExternal,"Print-" & DateTime.Now & ".pdf"))

Result - 0
My question was more of curiosity than anything. Like, for instance, the fact that the copy be bigger than the original could be due to the size of clusters, or something.

Meh..
 

Erel

Administrator
Staff member
Licensed User
File.Copy will not change the file size. It is possible that you are seeing some other effect.
However it is difficult to say more based on the code you posted.
 

Kiffi

Well-Known Member
Licensed User
@MitchBu : Try this, please

B4X:
Dim SourceFile As String = "1.pdf"
Dim TargetFile As String = "Print-" & DateTime.Now & ".pdf"

If File.Exists(File.DirInternal, SourceFile) = True Then
  File.Copy(File.DirInternal, SourceFile, File.DirDefaultExternal, TargetFile)
  Log("Size of SourceFile: " & File.Size(File.DirInternal, SourceFile))
  Log("Size of TargetFile: " & File.Size(File.DirDefaultExternal, TargetFile))
Else
  Log("SourceFile doesn't exists")
End If
Greetings ... Peter
 

MarkusR

Well-Known Member
Licensed User
i think i have two reason.
the file was not overwritten, delete it first and be sure its gone.
if you look the files at pc, to not trust this virual file system. maybe reboot windows.
 
Top