Home › Forum › Omnis General Forum › Simple problem but i can’t solve it.
Tagged: General Coding
-
Simple problem but i can’t solve it.
Posted by Ghiara Mimmo on January 9, 2020 at 8:13 amHello to all
i have a simple problem but i can’t solve it.
I have to save a text file on the desk
MacOsx 10.11
Omnis 8.03
HI 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
MimmoPaul Mulroney replied 4 years, 6 months ago 3 Members · 7 Replies -
7 Replies
-
I 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.jsp
Best of luck! -
Hello
I modified the code according to your instructions, now the code is like this
lnomefile 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 suggestions
Mimmo Ghiara -
Remember 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. -
For 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. -
Hello
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 character
Calculate xtextbin as the return
Do FileOps.$Converthfspathtoposixpath (lname, lposxfile) Returns lError
Do FileOps.$Writeentirefile (lposxfile, xtextbin) Returns lError
Result
Erorre = 998 (unknown)
Created a file but empty
I 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
Mimmo -
Hi 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 If
Log in to reply.