Copying a file results in empty file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Copying a file results in empty file
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
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
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!
Best
Klaus
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!

Best
Klaus
-
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Re: Copying a file results in empty file
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
Was missing a slash in the from path just before the filename.
Thanks Klaus

-
- VIP Livecode Opensource Backer
- Posts: 10057
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Copying a file results in empty file
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":
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.
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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Re: Copying a file results in empty file
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
-
- VIP Livecode Opensource Backer
- Posts: 10057
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Copying a file results in empty file
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.
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
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
-
- Posts: 738
- Joined: Thu Sep 11, 2014 1:49 pm
Re: Copying a file results in empty file
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.
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.