Tuesday, August 20, 2013

Changing backslashes to forward slashes changes file size

Changing backslashes to forward slashes changes file size

I have two small to medium sized files (2k) that are for all intents and
purposes identical. The second file is the result of the first file being
duplicated and replacing backslashes with forward slashes. The new file is
bigger by 80 bytes (or one byte per line).
I did this with a simple batch script,and at first I thought the script
might have unintentionally added some spaces or other artifacts. Or maybe
the fact that their extensions are different has something to do with it
(one has a tmp extension and the other has a lst extension).
From an editor, I replaced all forward slashes in the new file with
backslashes and saved it without changing the extension.
And, hey guess what? The files were the same size again.
Now, before this is written off as a random fluke, I also see the same
behavior exhibited in three other pairs of files (in other words six
files) created in the same manner as the first. They are all one byte
bigger per line in the file. The largest is about 12k bytes, and the
smallest is about 2k.
I wouldn't think it has anything to do with escaping because I am on a
Windows box using the Windows 7 cmd.exe shell.
Also one other thing. I tried the following:
echo \\\\\ >> a.txt
echo ///// >> b.txt
The files matched in size (7 bytes)
Does anyone have an explanation for this behavior?

No comments:

Post a Comment