Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: notepad  (Read 3975 times)

0 Members and 1 Guest are viewing this topic.

dos_newbie

  • Guest
notepad
« 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...

Sidewinder



    Guru

    Thanked: 139
  • Experience: Familiar
  • OS: Windows 10
Re: notepad
« Reply #1 on: December 16, 2008, 04:50:30 AM »
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.  8)

Creating files with VBScript and sendkeys is very inefficient.
The true sign of intelligence is not knowledge but imagination.

-- Albert Einstein

fireballs



    Apprentice

  • Code:Terminal
  • Thanked: 3
    Re: notepad
    « Reply #2 on: December 16, 2008, 06:37:48 AM »
    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
    Next time google it.