Copy link to clipboard
Copied
I'm using a text file to keep a number that is used in controlled documents.
For example file contents can be: 17-154. So when we need to create a new controlled document it will be 17-155 and so forth.
All that works fine, but:
- What if the text file does not exist?
I would like to create a text file from scratch and write '17-001' to it...
Any ideas?
Thanks guys.
1 Correct answer
var oFile = new File( sFileName );
oFile.encoding = "UTF-8";
if( !oFile.open('w'){
alert( "Cannot create file: " + sFileName );
return false;
}
oFile.writeln( "Whatever you want to write to the file" );
oFile.close( );
If you want to append text to an existing file, use oFile.open('a') instead. Don't forget to close the file after writing to it.
Good luck
Jang
Copy link to clipboard
Copied
var oFile = new File( sFileName );
oFile.encoding = "UTF-8";
if( !oFile.open('w'){
alert( "Cannot create file: " + sFileName );
return false;
}
oFile.writeln( "Whatever you want to write to the file" );
oFile.close( );
If you want to append text to an existing file, use oFile.open('a') instead. Don't forget to close the file after writing to it.
Good luck
Jang
Copy link to clipboard
Copied
Thanks 4everJang​,
So, you actually open the file to create it...never would have guessed that...
Your code works great!
Have a great day!
f

