2

I made a simple LAN chat batch file, and i would like to know if there is an command that checks if a specific txt file is updated. The chat history is stored in log.dat and i want to have a sound notification or something like that when theres a new message.

@echo off
title LAN chat reader
call Color.bat

:read
call Color.bat
cls
type log.dat
timeout /t 3 /nobreak >nul
goto read

(im a noob, please tell me if this is possible)

Mr. Mocha
  • 43
  • 1
  • 10
  • This is a really crazy idea(a batch), but i like it thumbs up. :) – winner_joiner Oct 01 '15 at 19:50
  • You will not have a very effective chat program with the design you are pursuing. I have posted a rudimentary but effective chat batch script at http://stackoverflow.com/a/29967710/1012053. Each user gets two command windows - one where the user types messages, and the other where all new messages from all sources are displayed, each with a userName: prefix. – dbenham Oct 02 '15 at 00:11
  • I have a similar chat thing. 2 widows for reading/sending and one for the operator with admin options (such as color: saved in color.bat) – Mr. Mocha Oct 02 '15 at 16:01

2 Answers2

3

To check the file date/time use for and %%~t prefix:

@echo off
title LAN chat reader
setlocal enableDelayedExpansion

:read
    call Color.bat
    cls
    type log.dat

    for %%a in (log.dat) do set filetimesize=%%~tza
    :checkupdate
        ping -n 1 -w 100 localhost >nul
        for %%a in (log.dat) do if "!filetimesize!"=="%%~tza" goto checkupdate
    echo updated
    goto read
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
  • I tried this, but the window would shut instantly (im using an MP3-file instead of !FILENAME! is that the problem? – Mr. Mocha Oct 02 '15 at 16:21
  • 1. What is a `!FILENAME!`? 2. Do the standard thing: remove `@echo off` and run the batch file from a Command Prompt console to actually see what's wrong. – wOxxOm Oct 02 '15 at 16:25
  • sorry, forget about !FILENAME! I got this output: =%~ta not expected at this moment. – Mr. Mocha Oct 02 '15 at 17:30
  • ok, i used the updated code, but ran into 2 problems: 1 It wil only update once, then i have to restart it to see the newest chat messages. 2 Wheres the output? like "start example.mp3" (probaly stupid questions, but im not advanced at all) – Mr. Mocha Oct 02 '15 at 17:38
  • Updated the code. The time string had no seconds so I've added the file size into comparison. Didn't understand your second question but the log file is printed with `type` command. – wOxxOm Oct 02 '15 at 17:56
  • How can i trigger a command with this? thats my 2nd question. (Im sure its a dumb question) – Mr. Mocha Oct 02 '15 at 18:01
2

wOxxOm already gave a solution to check for an updated file.

Here is a way to produce a Sound:

copy con bell.txt

Then press the ALT-key enter 007 while keeping ALT pressed, then release the ALT key. ^G should appear on your Screen (= 0x07, which is a Bell), then press Ctrl-Z. This gives you a textfile with lenght = 1 Byte

Type bell.txt

will then beep.

EDIT an easier way to produce bell.txt: on commandline, enter echo ^G>bell.txt (to produce ^G press CTRL-G). This will create a three-byte-file (instead of the one-byte-file with the copy trick) (but that's only a line feed and should not disturb).

Stephan
  • 53,940
  • 10
  • 58
  • 91
  • Alternatively, you could put `ECHO ^G` into the .bat script. The "^G" is made by pressing Ctrl+G. Your editor might or might not cooperate in using control characters. Note that "G" is the seventh letter in the Roman alphabet. – lit Oct 01 '15 at 22:22
  • Or embed a vbscript code that either prints `chr(9)` directly to the console or makes a temporary file with the character. – wOxxOm Oct 02 '15 at 16:29