Copying a file results in empty file

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Copying a file results in empty file

Post by mrcoollion » Sat Dec 17, 2016 4:14 pm

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

Klaus
Posts: 14208
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Copying a file results in empty file

Post by Klaus » Sat Dec 17, 2016 4:20 pm

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

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Copying a file results in empty file

Post by mrcoollion » Sat Dec 17, 2016 5:33 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Copying a file results in empty file

Post by FourthWorld » Sat Dec 17, 2016 5:42 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Copying a file results in empty file

Post by mrcoollion » Sun Dec 18, 2016 12:06 pm

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

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10057
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Copying a file results in empty file

Post by FourthWorld » Mon Dec 19, 2016 8:09 pm

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.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

mrcoollion
Posts: 738
Joined: Thu Sep 11, 2014 1:49 pm

Re: Copying a file results in empty file

Post by mrcoollion » Mon Dec 19, 2016 9:37 pm

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.

Post Reply