Solved Writing a BAT file to use MS-DOS EDIT

December 15, 2011 at 02:02:49
Specs: Windows 7, i3 3.1GHz / 4 GB
Hey,

I'd like to use a *.bat to open a *.txt in MS-DOS EDITOR, save it, and close it.
So far I only got it to open. ("edit test.txt")

The reason being - "edit.com" saves *.txt files in a slightly different format than before.
Inwhich a new line is described as "0D 0A", while in the original file it's only described as "0A".
(When viewing in CMDs "debug" command)

If there's another way to change how indications of a new line are written, it would be great too!

Thanks in advance (:


See More: Writing a BAT file to use MS-DOS EDIT

Report •


#1
December 15, 2011 at 08:39:58
✔ Best Answer
Fun fact: EDIT.COM (and DEBUG.EXE) are legacy 16-bit applications. You won't be able to use them when you move to x64.

This VBScript will open any file you feed it, and convert any "\r" or "\n" to the standard line endings:

Set fso = CreateObject("Scripting.FileSystemObject")
For Each arg In WScript.Arguments
  fileTxt = fso.OpenTextFile(arg).ReadAll
  fileTxt = Replace(fileTxt, vbCrLf, vbLf)
  fileTxt = Replace(fileTxt, vbCr, vbLf)
  fso.OpenTextFile(arg, 2, True).Write Replace(fileTxt, vbLf, vbNewLine)
Next 'arg

How To Ask Questions The Smart Way


Report •

#2
December 18, 2011 at 06:10:53
Thank you!
But I have to admit, I don't have the first clue on how to use VBScript.
Where do I place the directory\file name?

While we're at it - is there a way for the script to update so it could edit a different file per month?
(We make a new one each month, and the file name is always the same, except the date - something like "M_2011_11" for Nov, and then "M_2011_12" for Dec, etc.)


Report •

#3
December 18, 2011 at 07:05:14
You just save the script as whatever.vbs. Then, just drag and drop whatever file you want processed onto the vbscript's icon. That's pretty much it. Don't drop folders onto it; the script would bomb if you did.

There's no visual feedback and I never bothered to put in any notification, so you'll just have to glance at the file's modified date to see when the script is done. Also note I have never ran this on a file greater than 1GB, and it probably would run out of memory if you tried.

How To Ask Questions The Smart Way


Report •

Related Solutions

#4
December 18, 2011 at 07:09:52
You're a genius!
Thank you so much :)

BTW - if I throw in a file after it's already been edited - it won't affect it, right?


Report •

#5
December 18, 2011 at 08:49:58
It'll rewrite the file, but it should leave everything as-is.

How To Ask Questions The Smart Way


Report •


Ask Question