0

I'm trying to create a simple script that will store all my daily Record Name - DNS History. Initially i came up with this script here.

@echo off
ipconfig /displaydns > temp.txt
find "Record Name" temp.txt > WebsitesVisited.txt
del temp.txt

The problem is that every time i run the bat file, it overrides the previous record name history, so what i want is to create a loop that will generate a different txt file each time i run this script (etc WebsitesVisited1.txt, WebsitesVisited2.txt... WebsitesVisited999.txt).

Any suggestions?

user3747357
  • 71
  • 1
  • 1
  • 3

1 Answers1

0
@echo off

    setlocal enableextensions

    set "baseName=WebsitesVisited"

    set "count=0"
    for /f "delims=%baseName%." %%a in (
        'dir /b /o-d "%baseName%*.txt" 2^>nul'
    ) do ( set /a "count=%%a+1" & goto saveData )

:saveData
    ipconfig /displaydns | find "Record Name" > "%baseName%%count%.txt"

Search the last matching file, retrieve the number part, increment and save to the new file

MC ND
  • 69,615
  • 8
  • 84
  • 126
  • Thanks mate! It did exactly as i wanted! If i may ask, is it possible for that report to be send directly to my email? Etc Generate the file as we just did and send the contents via email? – user3747357 Jun 17 '14 at 07:24