Computer Hope
Microsoft => Microsoft DOS => Topic started by: dos_newbie on December 15, 2008, 10:58:46 PM
-
Hi friends.. :)
I am new to dos.. and i am stuck...
Please give a sample code to
1.open
2.Delete contents
3.add new lines
4.save
a notepad in dos pro mt...
-
Notepad can be scripted, but not with batch code.
Set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run "notepad c:\temp\test.txt" 'Point to existing file
WScript.Sleep 1000
WshShell.AppActivate "test - Notepad" 'Must match window title(handle)
WScript.Sleep 1000
WshShell.SendKeys "^(a)"
WScript.Sleep 1000
WshShell.SendKeys "{DEL}"
WScript.Sleep 1000
WshShell.SendKeys "1. Open notepad"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500
WshShell.SendKeys "2. Delete contents"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500
WshShell.SendKeys "3. Add new Lines"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
WScript.Sleep 500
WshShell.SendKeys "4. Save"
WScript.Sleep 500
WshShell.SendKeys "{ENTER}"
WScript.Sleep 2500
WshShell.SendKeys "^(s)"
WScript.Sleep 500
WshShell.SendKeys "%(f)"
WScript.Sleep 2500
WshShell.SendKeys "x"
WScript.Sleep 500
Notes:
1. Script opens an existing file test.txt. Change if necessary.
2. Window handle format is filename - Notepad; filename does not contain the extension.
3. Script will overwrite existing file; take precautions if necessary
Good luck. 8)
Creating files with VBScript and sendkeys is very inefficient.
-
@echo off
rem open
start "" notepad "c:\path to file\test.txt"
rem delete contents
echo >test.txt
rem add new lines
echo.>>test.txt
rem no need to save, already done.
exit