1.

Solve : notepad?

Answer»

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.

Code: [Select]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.

Creating files with VBScript and sendkeys is very inefficient. Code: [Select]@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



Discussion

No Comment Found