This topic contains 7 replies, has 3 voices, and was last updated by Paul Mulroney 1 year, 1 month ago.
-
AuthorPosts
-
January 9, 2020 at 8:13 am #24099
Hello to all
i have a simple problem but i can’t solve it.
I have to save a text file on the deskMacOsx 10.11
Omnis 8.03HI wrote this
return is string (ES = “1223 dfee”)
xtextbin is binarry
condocodfisc is string
lzeri = “0000”
lnumdoc is string (Ex “5”)
lDir_1 = “MACINTOSH HD / Users / administrator / Desktop /”Calculate xtextbin as the return
Calculate lNomedoc as with (‘IT’, condocodfisc, ‘_’, lzeri, lnumdoc, ‘. Xml’)
Calculate lDir_1 as with (lDir_1, lNomedoc)Do FileOps. $ Writeentirefile (lDir_1, xtextbin) Returns lrit
lrit returns 0 but the file is not written
Do you have any suggestions?
Thank you
Mimmo
January 13, 2020 at 6:44 pm #24109I believe you have to do something like this to write the file (create, open, write, close).
Do lFileOps.$createfile(lDir_1)
Do lFileOps.$openfile(lDir_1,kFalse)
Do FileOps.$writeentirefile(lDir_1,xtextbin) Returns lError
Do lFileOps.$closefile()For binary files I believe you can do writing in one step using the WriteBinFile command
https://www.omnis.net/developers/resources/onlinedocs/index.jspBest of luck!
January 14, 2020 at 8:18 am #24110Thank’s
I try it
Mimmo
January 15, 2020 at 3:43 pm #24117Hello
I modified the code according to your instructions, now the code is like thislnomefile id Macintosh HD:users:administrator:desktop:nomefile.txt
Do lFileOps.$openfile(lnomefile,kTrue) Returns lError
Do lFileOps.$writecharacter(kUniTypeAnsiLatin1,lritorno) Returns lError
Do lFileOps.$closefile()lerror returns me O (zero) so OM file written, instead I can’t find the file anywhere
I tried to replace i: with \
but nothing same error but files saved none
If you have any other suggestionsMimmo Ghiara
January 15, 2020 at 8:34 pm #24120Remember returning 0 means the file did not write. It will return true if sorry i should have wrote that better in my code it’s not lError should be lOK to be more clear.
First we wabt to make sure the lritorno variable is in fact a string since you are using writecharacter instead of $writeentirefile.
If that is the case break it before
Do lFileOps.$writecharacter(kUniTypeAnsiLatin1,lritorno) Returns lError
See what this line returns:
Do lFileOps.$openfile(lnomefile,kTrue) Returns lError
If it returns 0 (this is false) the file does not exist and you will need to use the Do lFileOps.$createfile() first if the file doesn’t exist.
Lastly make sure the variable lFileOps is an object reference mapped to the FileOps object.January 20, 2020 at 8:07 am #24155For Omnis Studio 8.0 and above, you need to use POSIX style pathnames, which means that:
Macintosh HD:users:administrator:desktop:nomefile.txt
becomes
/Volumes/Macintosh HD/Users/administrator/Desktop/nomefile.txt
You can use the FileOps.$converthfspathtoposixpath() function to convert if you’d prefer.
A man rushed into the doctor’s office and shouted, “Doctor! I think I’m shrinking!”
The doctor calmly responded, “Now, settle down. You’ll just have to be a little patient.”Paul W. Mulroney
We Don't Do Simple Pty Ltd
ACN 161 009 374
Bentley Western Australia 6102January 30, 2020 at 8:17 am #24349Hello
thanks for the help, I don’t seem to know how to program with Omnis Studio anymore.
I followed my advice and wrote:Do FileOps.$Converthfspathtoposixpath (lname, lposxfile) Returns lError
Do lFileOps.$Openfile (lfilename, kTrue) Returns lError
Do lFileOps.$Writecharacter (kUniTypeAnsiLatin1, lritorno) Returns lError
Do iFileOps.$Close ()Error result 0 but no file created
So I wrote so
xtextbin is binary
the return is characterCalculate xtextbin as the return
Do FileOps.$Converthfspathtoposixpath (lname, lposxfile) Returns lError
Do FileOps.$Writeentirefile (lposxfile, xtextbin) Returns lErrorResult
Erorre = 998 (unknown)
Created a file but emptyI no longer know what to do with files I have generated many with Omnis na I have never found these difficulties
If you have any other suggestions
MimmoJanuary 30, 2020 at 8:42 am #24350Hi Mimmo,
If you need to create the file, then you need to swap $openfile() for $createfile()
$openfile() will open an existing file, but it won’t create a new file. if you pass kTrue as the second parameter, it will open the file read-only and you will not be able to write to it.
It’s probably a good idea to test the lError between each line of code as it executes, you can check to see if the command fails.
So, your code should look something like this:
Do FileOps.$Converthfspathtoposixpath(lName,lposxfile)
If lposxfile=”
OK message {Could not convert file path [lName]}
Else
Do lFileOps.$createfile(lposxfile) Returns lError
If not(lError)
OK message {Could not create [lposxfile]}
Else
Do lFileOps.$Writecharacter(kUniTypeAnsiLatin1,lritorno) Returns lError
If not(lError)
OK message {Could not write to the file [lName]}
End If
Do lFileOps.$closefile()
End If
End IfA man rushed into the doctor’s office and shouted, “Doctor! I think I’m shrinking!”
The doctor calmly responded, “Now, settle down. You’ll just have to be a little patient.”Paul W. Mulroney
We Don't Do Simple Pty Ltd
ACN 161 009 374
Bentley Western Australia 6102 -
AuthorPosts
You must be logged in to reply to this topic.