Shoutbox

OpenTextFile & DeleteFile - Printable Version

-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: OpenTextFile & DeleteFile (/showthread.php?tid=80726)

OpenTextFile & DeleteFile by personne3000 on 01-05-2008 at 05:00 PM

Well... What would be said.. Hi?

I'm French and not so good at speaking English. So I won't spend my time writing a long message...

Why do these two codes give different results?


code:
fso.DeleteFile(chemin_fichier_calendrier);
fichier2 = fso.CreateTextFile(chemin_fichier_calendrier, 2, false);


code:
fichier2 = fso.CreateTextFile(chemin_fichier_calendrier, 2, true);

The file at "chemin_fichier_calendrier" always exists when these instructions are read.
Isn't the "true" parameter at the end of the "CreateTextFile" command supposed to overwrite the existing file?

The first possibility is the one that works for me. The second one gives... strange results, the output file isn't as I expect it to be (unexpected spaces and characters that I can't find on my keyboard...).

Thx :D
RE: OpenTextFile & DeleteFile by Matti on 01-06-2008 at 09:39 AM

You have your parameters wrong:

code:
FileSystemObject.CreateTextFile
object.CreateTextFile filename [, overwrite[, unicode]]
That means:
  • filename is the path to the file to be created.
  • overwrite is a Boolean defining whether the existing file may be overwritten.
  • unicode is a Boolean defining whether the text file should be saved as Unicode (true) or AscII (false, default).
That means that the '2' is interpreted as a Boolean for the overwrite parameter and becomes converted to 'true', and that the 'true' or 'false' in your last parameter actually changes the text encoding. This is what causes your "strange characters" (which aren't strange at all, in fact).

To fix this, just leave out the invalid '2' parameter. This way, your true/false are correctly sent as overwrite parameter. :)
code:
fichier2 = fso.CreateTextFile(chemin_fichier_calendrier, true); //Allow overwrite
fichier2 = fso.CreateTextFile(chemin_fichier_calendrier, false); //Don't allow overwrite

RE: OpenTextFile & DeleteFile by personne3000 on 01-06-2008 at 11:33 AM

OOhh right !

I think I used Ctrl + C - Ctrl + V a little bit too much :p
I had copied the syntax of "OpenTextFile" actually..

var Mefile = ObjSys.OpenTextFile(path, [ Mode [, Create? [, Format]]])

The "2" was supposed to be the mode (ForWriting) but I guess I just don't need it.

Thx :D

(And sorry about the language... I'm doing my best :P)