How to create a new file using DzFile ?
ratus69_c6741fefbf
Posts: 34
hello,
I'm having hard time trying to create a simple .ini file
I know how to read or write an existing file but cannot achieve to create a new one...
var path_file_daz_ini = " B:\\- ALBUM -\\Page 03\\5.Obj\\p03c08_joao.ini"function create_daz_ini(srcFilePath) { var srcFile = new DzFile(srcFilePath); print (srcFilePath) if (!srcFile.open(DzFile.ReadOnly)) { MessageBox.critical("Could not open file.", "Open File", "&OK", ""); return; } srcFile.close(); } create_daz_ini(path_file_daz_ini)
thanks for your help
Post edited by ratus69_c6741fefbf on
Comments
The line
needs a different access type. DzFile.ReadOnly makes it only read/open from an existing file. Use either DzFile.ReadWrite, or DzFile.WriteOnly, or DzFile.Append, or DzFile.Truncate.
(see http://docs.daz3d.com/doku.php/public/software/dazstudio/4/referenceguide/scripting/api_reference/object_index/file_dz )
In your sample, your use of
DzFile.ReadOnly
should be replaced withDzFile.WriteOnly
,DzFile.ReadWrite
orDzFile.Append
(as appropriate). Here is a tweaked version that will create a file named "testing.txt" at the root of the D drive:You may also want to take a look at the Install Manager Config (from DAZ Studio) sample. Particularly the
writeInstallManagerConfig
function.-Rob
Edit: Apparently I had this response open in a browser tab for nearly 45 min (cross-posted). Hmm... multi-tasking.
thanks to both of you hphoenix and Rob
in fact I have used the DzFile.WriteOnly arg with an other example but with no success
I have taken the function from Rob and put it in my script and it was not working but the whole example was...
Finally I discovered that there were a space in my path between the " and the path :
very stupid error...
anyway, thanks to both of you again !!