<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx</link><description>OK, back to scripting today. 
 But before I get back to scripting issues, one brief correction. An attentive reader noted that "The Well-Tempered Clavier" was in fact designed to sound good on a "well tempered" instrument, not an "equally tempered" instrument</description><dc:language>en-US</dc:language><generator>Telligent Evolution Platform Developer Build (Build: 5.6.50428.7875)</generator><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#9986713</link><pubDate>Mon, 29 Mar 2010 14:43:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9986713</guid><dc:creator>Gerardo Lima</dc:creator><description>&lt;p&gt;The code described in [&lt;a rel="nofollow" target="_new" href="http://www.asp101.com/articles/jacob/scriptupload.asp"&gt;http://www.asp101.com/articles/jacob/scriptupload.asp&lt;/a&gt;] does the job just right for uploading files to a server using only vbscript and standard TextStream objects(1). The only catch is that it must run under the following page directive &amp;lt;%@ CODEPAGE=&amp;quot;65001&amp;quot;; %&amp;gt;.&lt;/p&gt;
&lt;p&gt;(1) as returned by fso.CreateTextFile;&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9986713" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#9924803</link><pubDate>Wed, 18 Nov 2009 22:37:25 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9924803</guid><dc:creator>Kirby L. Wallace</dc:creator><description>&lt;p&gt;I use FSO and ADO.Streams for most of my binary file ops already. &amp;nbsp;But... &amp;nbsp;A comment here...&lt;/p&gt;
&lt;p&gt;The problem you seem to be describing here doesn't seem to have so much to do with the FileSystemObject, but rather with a quirky behaviour in the CHR() function. &amp;nbsp;The fso seems to happily, and binarily, write your binary file without hesitation. &amp;nbsp;It only broke down when you tried to make the CHR() function do something it isn't supposed to do. &amp;nbsp;&lt;/p&gt;
&lt;p&gt;Wouldn't an ADO stream have done the same thing with that same input?&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9924803" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#9602240</link><pubDate>Mon, 11 May 2009 13:17:45 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:9602240</guid><dc:creator>Michele Fiorantino</dc:creator><description>&lt;p&gt;Scriptable Byte Array &amp;nbsp;&lt;/p&gt;
&lt;p&gt; Function CreateByteArray(nsize)&lt;/p&gt;
&lt;p&gt;Dim sBin&lt;/p&gt;
&lt;p&gt;Set sBin = CreateObject(&amp;quot;Adodb.Stream&amp;quot;)&lt;/p&gt;
&lt;p&gt;sBin.Open&lt;/p&gt;
&lt;p&gt;sBin.Type = 2 ' adTypeText = 2&lt;/p&gt;
&lt;p&gt;sBin.WriteText String(nsize, Chr(0))&lt;/p&gt;
&lt;p&gt;sBin.Position = 0&lt;/p&gt;
&lt;p&gt;sBin.Type = 1 ' adTypeBinary&lt;/p&gt;
&lt;p&gt;CreateByteArray = sBin.Read(nsize)&lt;/p&gt;
&lt;p&gt;sBin.Close &lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=9602240" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#8737502</link><pubDate>Wed, 16 Jul 2008 11:35:23 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8737502</guid><dc:creator>12demons</dc:creator><description>&lt;p&gt;ups. Sorry ... a typo in the code. just replace:&lt;/p&gt;
&lt;p&gt;strTransform[i] = strContent.charCodeAt(0);&lt;/p&gt;
&lt;p&gt;into&lt;/p&gt;
&lt;p&gt;strTransform[i] = strContent;&lt;/p&gt;
&lt;p&gt;I use charCodeAt to play around with ASCII code .....&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8737502" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#8737498</link><pubDate>Wed, 16 Jul 2008 11:32:31 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8737498</guid><dc:creator>12demons</dc:creator><description>&lt;p&gt;hem. just test that FileSystemObject can be use to READ and WRITE binary file. only that you had to CHEAT a little. Instead of using ReadAll() just use recursice Read() to the file Size. a little snippet in JScript:&lt;/p&gt;
&lt;p&gt;-- Code Start --&lt;/p&gt;
&lt;p&gt;var objFileSystem = new ActiveXObject('Scripting.FileSystemObject');&lt;/p&gt;
&lt;p&gt;var objFileIO = objFileSystem.GetFile('pack.exe');&lt;/p&gt;
&lt;p&gt;var streamIO = objFileIO.OpenAsTextStream();&lt;/p&gt;
&lt;p&gt;var strTransform = new Array();&lt;/p&gt;
&lt;p&gt;for (i=0;i&amp;lt;objFileIO.Size;i++) {&lt;/p&gt;
&lt;p&gt;	var strContent = streamIO.Read(1);&lt;/p&gt;
&lt;p&gt;	strTransform[i] = strContent.charCodeAt(0);&lt;/p&gt;
&lt;p&gt;	}&lt;/p&gt;
&lt;p&gt;streamIO.Close();&lt;/p&gt;
&lt;p&gt;objFileIO = objFileSystem.CreateTextFile('dumb.exe', true);&lt;/p&gt;
&lt;p&gt;for (i=0;i&amp;lt;strTransform.length;i++) { objFileIO.Write(strTransform[i]); }&lt;/p&gt;
&lt;p&gt;objFileIO.Close();&lt;/p&gt;
&lt;p&gt;-- Code End --&lt;/p&gt;
&lt;p&gt;Basicaly copy pack.exe into Array then write Array into dumb.exe&lt;/p&gt;
&lt;p&gt;Surprisingly both are identical and executable. Isn't strange?&lt;/p&gt;
&lt;p&gt;All i need now is smart way to play with the Array .... &lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8737498" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#8434888</link><pubDate>Mon, 28 Apr 2008 12:02:19 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:8434888</guid><dc:creator>William Shakespeare</dc:creator><description>&lt;p&gt;If ADODB.Stream is a solution.&lt;/p&gt;
&lt;p&gt;I dont know what is much ado aabout nothing means.&lt;/p&gt;
&lt;p&gt;/****************************************************************************/&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Option Explicit&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Dim sServer, sDatabase, sUsername, sPassword&lt;/p&gt;
&lt;p&gt; &amp;nbsp;sServer &amp;nbsp; = &amp;quot;servername&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;sDatabase = &amp;quot;database&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;sUsername = &amp;quot;username&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;sUsername = &amp;quot;password&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Dim UDL&lt;/p&gt;
&lt;p&gt; &amp;nbsp;UDL = ReadBinaryFile(&amp;quot;Old.udl&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;UDL = SetValue(UDL, &amp;quot;Data Source&amp;quot;, sServer)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;UDL = SetValue(UDL, &amp;quot;Initial Catalog&amp;quot;, sDatabase)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;UDL = SetValue(UDL, &amp;quot;User ID&amp;quot;, sUsername)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;UDL = SetValue(UDL, &amp;quot;Password&amp;quot;, sPassword)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;UDL = SaveBinaryData(&amp;quot;New.udl&amp;quot;, UDL)&lt;/p&gt;
&lt;p&gt;' =================================================================&lt;/p&gt;
&lt;p&gt;' Function to read text from a binary (unicode) file&lt;/p&gt;
&lt;p&gt;' =================================================================&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Function ReadBinaryFile(FileName)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Const adTypeBinary = 1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Dim BinaryStream&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Set BinaryStream = CreateObject(&amp;quot;ADODB.Stream&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.Type = adTypeBinary&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.Open&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.LoadFromFile FileName&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; ReadBinaryFile = BinaryStream.Read&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.Close&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Set BinaryStream = Nothing&lt;/p&gt;
&lt;p&gt; &amp;nbsp;End Function&lt;/p&gt;
&lt;p&gt;' =================================================================&lt;/p&gt;
&lt;p&gt;' Function to write a modified string back to a unicode file&lt;/p&gt;
&lt;p&gt;' =================================================================&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Function SaveBinaryData(FileName, Text)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Const adTypeBinary = 1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Const adTypeText = 2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Const adSaveCreateOverWrite = 2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Dim BinaryStream&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Set BinaryStream = CreateObject(&amp;quot;ADODB.Stream&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.Type = adTypeBinary&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.Open&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; With CreateObject(&amp;quot;ADODB.Stream&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Type = adTypeText&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Open: .WriteText Text&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Position = 2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.CopyTo BinaryStream, Len(Text) * 2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Close&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; End With&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.SaveToFile FileName, adSaveCreateOverWrite&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; BinaryStream.Close&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Set BinaryStream = Nothing&lt;/p&gt;
&lt;p&gt; &amp;nbsp;End Function&lt;/p&gt;
&lt;p&gt;' =================================================================&lt;/p&gt;
&lt;p&gt;' Function replace semicolon delimited values in a unicode string&lt;/p&gt;
&lt;p&gt;' =================================================================&lt;/p&gt;
&lt;p&gt; &amp;nbsp;Function SetValue(Data, Key, Value)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Dim Text, Prefix, Suffix, i&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; If Len(Value) = 0 Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SetValue = Data&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; Else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Drop leading character&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Text = Mid(Data, 2)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i = InStr(Text, Key)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Prefix = Left(Text, i + Len(Key))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Suffix = Mid(Text, i + Len(Key))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;i = InStr(Suffix, &amp;quot;;&amp;quot;)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if i = 0 Then&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Suffix = &amp;quot;&amp;quot;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;Else&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; Suffix = Mid(Suffix, i)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;'Restore leading character and concatinate new value&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;SetValue = Left(Data, 1) + Prefix + Value + Suffix&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; End If&lt;/p&gt;
&lt;p&gt; &amp;nbsp;End Function&lt;/p&gt;
&lt;p&gt;July 11, 2006 7:11 PM &lt;/p&gt;
&lt;p&gt;/****************************************************************************/&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=8434888" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#7630896</link><pubDate>Tue, 12 Feb 2008 07:17:04 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:7630896</guid><dc:creator>Ian Freeman</dc:creator><description>&lt;p&gt;I came across newObjects' AXPack1 when I found out that Windows CE doesn't have FSO. It seems to have great support for Binary files. It's free too.&lt;/p&gt;
&lt;p&gt;Check out this VBS sample:&lt;/p&gt;
&lt;p&gt;Dim fso, file, BD, BoM&lt;/p&gt;
&lt;p&gt;Set fso = CreateObject(&amp;quot;newObjects.utilctls.SFMain&amp;quot;)&lt;/p&gt;
&lt;p&gt;Set file = fso.OpenFile(filename)&lt;/p&gt;
&lt;p&gt;Set BD = CreateObject(&amp;quot;newObjects.utilctls.SFBinaryData&amp;quot;)&lt;/p&gt;
&lt;p&gt;BD.Value = file.ReadBin(2) &amp;nbsp; 'read first 2 bytes&lt;/p&gt;
&lt;p&gt;BoM = BD.Data(0,1) &amp;nbsp; 'convert first 2 bytes to byte array&lt;/p&gt;
&lt;p&gt;file.Close()&lt;/p&gt;
&lt;p&gt;bom now contains the byte order mark of filename in a VT_UI | VT_ARRAY byte array.&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=7630896" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#5473141</link><pubDate>Tue, 16 Oct 2007 20:09:42 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5473141</guid><dc:creator>Ben</dc:creator><description>&lt;p&gt;Surely it is better to call it MBCS-land... and anyway, aren't we all in an MBCS land these days? Everything except the most basic of basic text files (that do not include any currency symbols other than the dollar sign ;-))&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=5473141" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#2845576</link><pubDate>Thu, 24 May 2007 19:56:28 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2845576</guid><dc:creator>Blue Streak</dc:creator><description>&lt;p&gt;Try using an HTA or VBS file.&lt;/p&gt;
&lt;p&gt;IE6 block dynamic content (i.e. scripts) in HTM, HTML files&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2845576" width="1" height="1"&gt;</description></item><item><title>re: Binary Files and the File System Object Do Not Mix</title><link>http://blogs.msdn.com/b/ericlippert/archive/2005/04/20/binary-files-and-the-file-system-object-do-not-mix.aspx#2689894</link><pubDate>Thu, 17 May 2007 10:09:26 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2689894</guid><dc:creator>P.G.</dc:creator><description>&lt;p&gt;I have ie6 on my machine. I tried using adodb.stream from vbs for manipulating&lt;/p&gt;
&lt;p&gt;binary files. I understand that adodb.stream is not getting recognized and &lt;/p&gt;
&lt;p&gt;I am unable to save or read binary files through this. any ideas??&lt;/p&gt;
&lt;div style="clear:both;"&gt;&lt;/div&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2689894" width="1" height="1"&gt;</description></item></channel></rss>