Page 1 of 1

Copying a file results in empty file

Posted: Sat Dec 17, 2016 4:14 pm
by mrcoollion
I need to copy a template database to the actual working location if the stack is started at the first time.
However i do get a copy of the database but the file is empty (0 kb) .
When I copy it manual all goes fine.

Any reason why this is the case? Any ideas on solutions or what I am doing wrong?

I tried do this with both below options and bot give the same empty file as a result:

Option 1) put url("binfile:"&CopyFromPathAndFile) into url("binfile:"&CopytoPathAndFile)

Option 2) revCopyFile CopyFromPathAndFile,CopyToPath

Regards,

Paul

Re: Copying a file results in empty file

Posted: Sat Dec 17, 2016 4:20 pm
by Klaus
Dag Paul,

please tell us where the source file and target file are exactly located on the machine.
Maybe this is a permission problem?

And what doe "the result" say, which you check immediately after the copy action, of course! 8)


Best

Klaus

Re: Copying a file results in empty file

Posted: Sat Dec 17, 2016 5:33 pm
by mrcoollion
The result gave me no error but found the problem thanks to your suggestion to check the path names.
Was missing a slash in the from path just before the filename.

Thanks Klaus :D

Re: Copying a file results in empty file

Posted: Sat Dec 17, 2016 5:42 pm
by FourthWorld
If you checked "the result" immediately after the file I/O command, it would contain an error string. Perhaps your code checked it a statement or two later after it cleared? "The result" is usually very reliable. If you find an exception it would be a bug, but without seeing your code it's impossible to say, and historically bugs with "the result" are very rare.

With file I/O and other things like sockets that depend on the OS, it's very helpful to include a call to the sysError function along with a check of "the result":

Code: Select all

put "somedata" into url "file:/path/to/file.txt"
if the result is not empty then
   answer "Error: "& the result &" ("& sysError() &")"
   exit to top
end if
SysError returns the OS-specific error code from which you can identify the specific reason the OS was unable to do what LiveCode was asking it to do.

Re: Copying a file results in empty file

Posted: Sun Dec 18, 2016 12:06 pm
by mrcoollion
This is the code I use:

Code: Select all

put RCRPSv001["ApplicationPath"]&RCRPSv001["ClientDatabaseName"] into CopyFromPathAndFile
put RCRPSv001["DataBasePath"] into CopyToPath
put RCRPSv001["DataBasePath"] & RCRPSv001["ClientDatabaseName"] into  CopytoPathAndFile
--put url("binfile:"&CopyFromPathAndFile) into url("binfile:"&CopytoPathAndFile)
revCopyFile CopyFromPathAndFile,CopyToPath
put the result into tResult
answer "put the result into tResult = "&tResult&cr&" CopyFromPathAndFile = "&CopyFromPathAndFile&cr&"CopytoPathAndFile = "& CopytoPathAndFile

Re: Copying a file results in empty file

Posted: Mon Dec 19, 2016 8:09 pm
by FourthWorld
Testing revCopyFile here I find that "the result" is not empty when given an invalid path.

However, what it returns is not a string describing the error, as is customary with most commands in LiveCode, so I added a note about this to an existing report on a related issue:
http://quality.livecode.com/show_bug.cgi?id=5859

That said, the return value when given an invalid path is "1", not empty. Are you seeing a value there? If you're seeing an empty string being returned in "the result" we'll have to see if we can figure out a way to reproduce that. Trying here, I haven't found one yet.

Re: Copying a file results in empty file

Posted: Mon Dec 19, 2016 9:37 pm
by mrcoollion
In my case I forgot to put an extra \ at the end of the path string before I pasted the filename behind it.
This means that the path exists but the expected file does not exist (that is what it seems from revCopyFile point of view )

Maybe that is why "the result" is empty.