由于缺乏有用的评论而结束了绳索
我正在尝试编写一系列代码,在更新文件时进行注册,然后显示更新的文件。我尝试了很多东西,没有任何工作。有没有办法检查文件的更新,然后运行命令(如果有的话),如果没有则等待更改?
更新: 我意识到我没有像我想象的那样提供尽可能多的信息。 我正在创建一个批处理文件,该文件将运行一个托管聊天室的本地网络驱动器。我创建了一个程序,您可以在其中输入聊天框和输出框。然后我有两个日志文件,一个用于登录用户登录,另一个用于用户消息。
当有人发表评论时,我需要消息屏幕来更新所有用户。我把它设置为每秒重新加载,但这有点让人眼前一亮。
有没有什么办法可以告诉读取文件一旦表明消息文件有变化就会循环回来?
谢谢你们帮我收到的帮助。
我感谢任何帮助。如果我错过了我需要添加的任何内容,请告诉我。
答案 0 :(得分:1)
您应该为每个用户使用一个文件来检查状态。这样您就可以在自己的窗口中制作不同的广告。
聊天窗口不一定必须共享 - 但可以拆分它。
显示不必一次又一次地更新,仅在写入时激活,否则显示其他用户的消息或他们自己的设置。
状态信息通过窗口标题显示。
最后但并非最不重要的是,使用find或更多信息从共享聊天文件中读取消息。当然你可以用robocopy做到这一点,但是如果它足够快......
您可以将其全部扩展,以便为每个已发送的消息创建每个用户的控制文件。这反过来将允许robocopy容易地监视这样的控制文件。然后像往常一样在cli中显示以下聊天记录并删除控制文件。这应该至少让批次平静下来。
我有一个非常古老的聊天程序(我在培训期间写过它与其他人聊天,我很无聊)。 它使用可下载的choice.exe,它必须与脚本放在同一目录中。 当然,我今天会以完全不同的方式编写它,因此它适用于xcopy而不是choice(关键字SnakeBatch)。但我太懒了。我添加了一些评论......
而且我也承认这个剧本编写得不好 - 但它只是陈旧,特别和丑陋。由于这个脚本已经在我的文件中存在了一段时间 - 我认为我没有编写脚本编写服务(可能其他人原谅我)。是的,它有点过于问题,但它是什么......
@echo off
cls
setlocal
rem Vars: color text - backround
set "LC=f"
set "BC=0"
set "Full= "
color %BC%%LC%
set "NameSearch=%~n0"
set "NameSearch=%NameSearch:~,-1%?%~x0"
ver |find " XP " >nul && (set "UEB="
set "XP=/c:"::x [\!One!]""
)
ver |find " XP " >nul || set "UEB=1" &&set "XP=/c:"::v [\!One!]""
:: Freigabe schon verfügbar ?
::net use
::net share
mountvol|find /i ":\">"%temp%\test"
for %%i in (a b c d e f g h i j k l m n o p q r s t u v w x y z) do (
find /i "%%i:\" "%temp%\test">nul || for /f "delims=" %%k in ('
" for /r "%%i:\" %%j in ("%Namesearch%") do if "%~nx0" == "%%~nxj" echo "%%j" "
') do set "LWShare=%%~dpk"
)
rem status file switch
:: Nur eine Datei davon maximal Vorhanden
:: --------------------------------------
:: Batch Chat User Angemeldet ".bca"
:: Batch Chat User Schreibt ".bcw"
:: Batch Chat User Offline ".bco" rem NOT in use: list old/unused names
:: Batch Chat User Idle ".bci"
::
rem status file beep
:: Batch Chat User Ring ".bcr"
rem NOT in use: only test file switch - private , timer
:::: nach der Anmeldung immer Vorhanden
:::: --------------------------------------
:::: Batch Chat User Timer ".bct"
:::: Batch Chat User Privat ".bcp"
rem color code
:: code Farbe Bedeutung Schrift H-grund
:: 0 Schwarz Andere Anwesend x
:: 8 D-Grau Allein Anwesend x
:: 1 D-Blau Anderer Benutzer schreibt x
:: 7 H-Grau Option Aus x
:: f Weis Option Ein/Eingabe Fertig x
:: c Rot Erkennung eines Befehles x
:: a Grün Benutzer schreibt x
:: b Zyan <Benutzer : Meldung> x
:: d Magenta Modus Idle x
:: e Gelb Nachricht Erhalten x
:: 2 D-Grün
:: 3 BlauGrün
:: 4 D-Rot
:: 5 Lila
:: 6 Ocker
:: 9 Blau
::goto :begin
:settings
rem idle message - file = .bci
rem write message - file = .bcw
rem self - idle info message
rem self - write info message
rem self - alone info message
set "IdleInfo=... liegt grad sinnlos herum"
set "WriteInfo=... schreibt gerade"
set "MyIdleInfo=... Ich mach grad eine 15"
set "MyWriteInfo=: Ich Schreibe gerade etwas ..."
set "AloneInfo=Du bist am Arsch der Welt"
:begin
if defined LWShare ( pushD "%LWShare%" ) else pushD "%~dp0"
rem Input variant choice.exe
if not exist "%temp%\choice.exe" copy /y /z choice.exe "%temp%\choice.exe" >nul||(echo Keine choice.exe im Verzeichnis vorhanden&pause&goto :eof)
title Chat for CMD-Line
echo Chat Server Laufwerk: "%cd%"
@echo off
set "Userin=%Username%"
echo\%Username%>"%temp%\test"
for /f "tokens=2 delims=. " %%i in ('" echo User 0& Dir /b /od "User *.bc?" 2>nul "') do (
for /f %%j in ('" set /a x=%%~ni + 1 "') do if not exist "User %%~j.*bc?" set "Userin=User %%j"
)
Dir /b "%username%.bc?" >nul 2>&1 && ( echo Sorry "%username%" Dein Name ist schon vergeben!
)
goto :Userin
rem NOT in use: method usernames - list old/unused names
:User
(for /f "delims=." %%i in ('" dir /b *.bco 2>nul && echo --- M”gliche Benutzernamen "') do echo %%i
)>"%temp%\file"
sort "%temp%\file"
:Userin
rem - list used usernames
(for /f "delims=." %%i in ('" dir /b *.bc? 2>nul |findstr /r /c:"[awi]$" && echo --- Belegte Benutzernamen "') do echo %%i
)>"%temp%\file"
sort "%temp%\file"
set "USER="
:Userin
rem username
set /p User="Waehle einen anderen Benutzernamen oder mit nur Enter waehle "%Userin%" "
setlocal enabledelayedexpansion
if not defined User set "User=%username%"
echo\!User!>"%temp%\test"
endlocal
findstr /v /r "[?.</>\\|:;%%=~*\[\]()&]" "%temp%\test"|findstr /v /r /c:"[ ]$"|findstr /v /r "^-" >nul || (cls & echo Nicht Verwertbare Zeichen gefunden!& goto :User )
if defined User findstr "[0-Z][0-Z][0-Z]" "%temp%\test" || echo Zu wenig Zeichen! Anderen Namen waehlen!&& Goto :User
if defined User Dir /b "%user%.bc?" "%user%.*.bc?" >nul 2>&1 && echo Benutzername "%User%" ist schon vergeben - anderen Namen waehlen!&& goto :User
if not defined User for /f "tokens=2 delims=. " %%i in ('" echo User 0& Dir /b /od "User *.bc?" 2>nul "') do if not defined User for /f %%j in ('" set /a x=%%~ni + 1 "') do if not exist "User %%~j.*bc?" set "User=User %%j"
@echo off
cls
for /f %%i in (' cmd /u /von /c"echo !user!"^|find /v ""^|findstr .^|find /c /v "" ') do call set "Free=%%Full:~%%i%%"
if not defined Free set "Free= "
if not exist Chat.log type nul > Chat.log
set "Spot=Echo\^<%User% : spot Befehl Erkennung^>"
set "Echo=1"
:ReFresh
set "LC=f"
set "BC=0"
color %BC%%LC%
setlocal enabledelayedexpansion
echo Hallo !user! ... Willkommen im Chat
for /f %%i in ('" Dir /b *.bc? 2>nul|findstr /v /r /c:"[.]bco$"|findstr /v /r /c:"^%User%[.]"|find /v /c "" 2>nul "') do if %%i equ 0 (echo Du bist der erste Hier! & if not defined Gr1 if exist Chat.log del Chat.log & type nul > Chat.log ) else echo Es sind bereits %%i Personen im Chat.&echo\&(for /f "delims=." %%i in ('" Dir /b /od *.bc? 2>nul|findstr /v /r /c:"^%User%[.]*bc"|findstr /r /c:"[.]bc[aiw]$" "') do echo %%~i)& echo und Du : !USER!
echo\&echo Zum Abmelden EXIT eingeben oder 0 Drcken
echo Fuer Hilfe HELP eingeben oder 1 Drcken
echo .......................................................................&echo\
type nul > "!User!.bca"
endlocal
if not defined Gr1 for %%i in (Chat.log) do set /a Gr = %%~zi , Gr1 = %%~zi
if not defined LL1 for /f %%i in ('" find /v /c "" < "Chat.log" 2>nul "') do set /a lastline = %%i , LL1 = %%i
::echo Vorher : %LL1% Nachher : %Lastline% Letztes Löschen: %LastClear% Naechstes Löschen : %OldClear%
if "%one%" == "ref" set /a Gr = Gr1 , lastline = LL1 & (if defined Lastclear set /a lastline=LastClear)&set "one="& goto :Anfang
:: echo on
setlocal enabledelayedexpansion
(
echo ^<!User! : Hat den Chat betreten ...^>
)>> Chat.log
endlocal
:Anfang
@echo off
if not defined Users (
for /f "delims=" %%i in ('" Dir /b /od *.bc? 2>nul | findstr /v /r /c:"[.]bc[wo]$" | findstr /v /r /c:"^%User%[.]" || Dir /b /od *.bcw >nul 2>nul || title Hallo "%USER%" %Info% %AloneInfo% "') do call set "Users=%%Users%%:%%~ni"
) && set "BC=0" || set "BC=8"
if not defined Write (
for /f "delims=" %%i in ('" dir /b /od *.bcw 2>nul "') do call set "Write=%%Write%%:%%~ni"
)
if not defined Wrote (
set "Wrote=1" & for /f "tokens=1* delims=:" %%i in ("%Write%") do set "Write=%%j" & Dir "%%~i.bcw" >nul 2>nul && title "%User%" %Info% Chat "%%i"
) else set "Wrote=" & for /f "tokens=1* delims=:" %%i in ("%Users%") do set "Users=%%j" & Dir "%%~i.bca" "%%~i.bci" >nul 2>&1 && title "%User%" %Info% Chat mit "%%i"
if exist *.bcw set "BC=1"
color %BC%%LC%
for %%h in ("%user%.*bcr") do for /f "usebackq delims=" %%i in ("%%~h") do del "%user%.*bcr"&echo ^<%%i: macht L„rm - Ring Ring Ring Ring Ring ... ^>&set "Ring=2")
if defined Ring <nul set /p "="&if "%ring%" == "0" (set "Ring=") else set /a Ring - = 1
for %%i in (Chat.log) do if "%%~zi" neq "%Gr%" (set /a Gr = %%~zi ) else goto :Write
if defined mIn set mIn=^|findstr /v /r /c:"^%user%[ ]*: " 2^>nul
for /f %%i in ('" find /v /c "" < "Chat.log" 2>nul "') do (
if %%i neq %lastline% ( set "LC=f"
if %%i lss %lastline% more +%LastClear% Chat.log| find /v ""
if %%i gtr %lastline% more +%lastline% Chat.log%mIn% | find /v "" && set "LC=e" && if defined one (
if defined Auto more +%lastline% Chat.log%mIn% |findstr /v /r /c:"^<.*>$" >nul 2>nul&& echo ^<%user% : Auto Message!! %time:~0,-3% : Bin net da!^>>>Chat.log&&(%Beep%
rem beep for incoming Message
)|| set "LC=b"
if not defined Auto more +%lastline% Chat.log%mIn% |findstr /v /r /c:"^<.*>$" >nul 2>nul&& (%Beep%
set "LC=e"
)|| set "LC=b"
)
set /a lastline = %%i
)
)
color %BC%%LC%
:Write
if defined Echo (
%BeepM%
%AutoM%
%Spot%
rem Optionen Anzeigen
)
set "Echo="
set "mIn="
%Message%
set "Message="
set "one="
@echo off
(
for /f "eol=" %%i in ('" %temp%\choice /cabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!$%%.,\`\`\"\"{}()?/\[]*#-+^=:;_'^^^&õ§@~ /n /s /t,1 "') do for /f "eol= delims=" %%j in ("%%i") do set "One=%%j"
) >nul
if not exist "%user%.bco" if exist "%User%.*bc?" ( if defined One call :WriteIn ) else goto :eof
if /i "%One%" == "ref" %bp%cls&goto :ReFresh
set "one="
if exist "*.bca" goto :Anfang
if exist "*.bcw" goto :Anfang
if exist "*.bci" goto :Anfang
set "LC=f"
set "BC=0"
color %BC%%LC%
goto :EOF
:WriteIN
::@echo off
set "Info="
set "LC=c"
if exist *.bcw set "BC=1"
title Chat von "%User%" : Eingabe erkannt
color %BC%%LC%
::@echo off
set "OneX="
set "oney="
:Check
setlocal enabledelayedexpansion
@echo off
if exist *.bcw set "BC=1"
color %BC%%LC%
::: Ersetze in v+7: z mit y + Tabelle
set "New="
set "OneX="
if not defined UEB goto :noUEB
if not defined one goto :noUEB
if !one! geq 0 if !one! leq x goto :noUEB
for /f "eol= tokens=2,3" %%i in ('findstr /b /r %XP% "%~f0"') do if not defined OneX if "%%i" == "!One!" set "OneX=%%j"&set "One="
:noUEB
set "One=!oney!!OneX!!One!"
set "OneX="&set "oney="
@echo off
for %%i in (
"1 help hel he h"
"2 cls cl c"
"3 ref re r"
"4 load loa lo l"
"5 idle idl id i"
"6 auto aut au a"
"7 beep bee be b"
"8 spot spo sp s"
"9 ring rin ri"
"0 exit exi ex e" ) do for /f "tokens=1,2*" %%j in ("%%~i") do (
if /i "%%j" == "!One!" ( set "One=" & set "New=%%k"
) else if defined Spot if /i "%%~k" == "!one!" ( set "New=!One!" && set "One="
) else for %%m in (%%~l) do if /i "%%m" == "!One!" set "OneX=!One!" && set "One="
)
if not defined OneX goto :NoCheck
title Chat von "%User%" : Eingabe Auto - Erkennung : ^<!OneX!^>
for /f "eol=" %%i in ("!OneX!") do endlocal & set "oney=%%i" & set "One="
rem input Variant
(
for /f "eol=" %%i in ('
" %temp%\choice /cabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ!$%%.,\`\`\"\"{}()?/\[]*#-+^=:;_'^^^&õ§@~ /n /s /t,1 "
') do for /f "eol= delims=" %%j in ("%%i") do set "One=%%j"
) >nul
goto :Check
:NoCheck
@echo off
if defined New goto :Idle
color %BC%a
for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.%WriteInfo%.bcw"
title Chat von "%User%" %MyWriteInfo%
set /p New=!User!%Free%: !One!
:Idle
set "LC=f"
if /i !one!!new! == IDLE for %%i in ("%User%.*bc?") do ren "%%~i" "!User!.!IdleInfo!.bci"& Echo\^<!User! : !one!!New!^>& endlocal & set "Info=%MyIdleInfo%" & set "LC=d" & goto :eof
if /i not !one!!New! == RING goto :NoRing
for %%i in ("%User%.*bc?") do ren "%%~i" "!User!.bci"
for /f "delims=." %%i in ('" dir /b *.bc? 2>nul |findstr /r /c:"[awi]$" "') do echo\!user! >"%%i.bcr"
endlocal&set "LC=f"
goto :eof
:NoRing
if /i not !one!!new! == CLS goto :NoCls
for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.bca"
cls
echo\^<!User! : Anzeige geleert^>
%BeepM%
%AutoM%
endlocal & set "LC=f" & set /a LastClear=lastline , OldClear=lastline & set "one=ref" & set "Echo=1" & goto :eof
:NoCls
if /i !one!!new! == BEEP for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.bca"& if defined Beep ( Echo\^<!User! : !one!!New! - AUS^>& endlocal & set "BeepM=" & set "Beep=" & set "LC=7" & goto :eof) else Echo\^<!User! : !one!!New!^>& endlocal & set "BeepM=Echo\^<%User% : %one%%New%^>"& set "Beep=<nul set /p =" & set "LC=f" & goto :eof
if /i !one!!new! == AUTO for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.bca"& if defined Auto ( Echo\^<!User! : !one!!New! Nachricht - AUS^>&endlocal&set "Auto="&set "AutoM="&set "LC=7"&goto :eof) else Echo\^<!User! : !one!!New! Nachricht^>& endlocal & set "Auto=1" & set "AutoM=Echo\^<%User% : %one%%New% Nachricht^>" & set "LC=f" & goto :eof
if /i not !one!!new! == HELP goto :NoHelp
rem Help message
set "LC=f"
set "BC=0"
color %BC%%LC%
for %%i in ("%User%.*bc?") do ren "%%~i" "!User!.bca"
title CMD Chatprogramm Hilfe
cls
findstr /b /c:"::: " "%~f0"
ping localhost -n 6 >nul & endlocal & set "One=ref" & set "Echo=1" & goto :eof
:NoHelp
:Exit
if /i !one!!new! == EXIT (for %%i in ("%User%.*bc?") do findstr . "%%~i" >nul || del "%%~i" >nul
echo ^<!User! Hat den Chat verlassen ...^>
)>> Chat.log & goto :eof
:Ref
if /i !one!!new! == REF for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.bca"&title Chat for CMD-Line&endlocal&set "One=ref"&set "LastClear=%OldClear%"&set "Echo=1"&goto :eof
:Load
if /i !one!!new! == LOAD for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.bca"&title Chat for CMD-Line&endlocal&set "One=ref"&set "OldClear=%LastClear%"&&set "LastClear="&set "Echo=1"&goto :eof
:Spot
if /i not !one!!new! == SPOT goto :NoSpot
for %%i in ("%User%.*bc?") do ren "%%~i" "%User%.bca"
title Chat for CMD-Line
endlocal
set "One="
if defined Spot (set "Spot="&Echo\^<%User% : spot Befehl Erkennung - AUS^>&set "LC=7") else set "Spot=Echo\^<%User% : spot Befehl Erkennung^>"&set "LC=f"
%Spot%
goto :eof
:NoSpot
set "New=!One!!New!"
if "!New:~0,-2!" == "" ren "%User%.%WriteInfo%.bcw" "%User%.bca"&title Chat for CMD-Line&endlocal&set "One=ref"&set "Message=echo ^<%user% : Nachricht zu kurz - Nichts gesendet ^>"&goto :eof
if not !New! equ !Old! (
echo !USER!%free%: !New!
)>> Chat.log else set "Message=echo ^<%user% : Kein Spam erlaubt - Nichts gesendet ^>"
for /f "delims=" %%i in ("!New!") do (endlocal
set "Old=%%i"
set "mIn=1"
set "Message=%Message%"
) || ( endlocal & set "Old=" & set "Message=%Message%")
if defined Message (set "one=ref") else set "One="
ren "%User%.%WriteInfo%.bcw" "%User%.bca"
title Chat for CMD-Line
set "LC=f"
goto :eof
::: Eingabe oder NR Das wird gemacht!
::: help 1 diese Hilfe des CMD-Chatprogamm
::: cls 2 Bilschirm leeren
::: ref 3 Bildschirm neu laden (ab cls)
::: load 4 Chatverlauf von Anfang laden
::: idle 5 Status auf besch„ftigt setzen
::: auto 6 Automatische Antwort Ein/Aus
::: beep 7 Empfangston Ein/Aus
::: spot 8 Befehlerkennung ohne Enter Ein/Aus
::: ring 9 Alle Anpiepen
::: exit 0 Chat Verlassen
:::
::: Zeichen welche im Chat Auf Beginn der Tastatureingabe Reagieren
:::
::: ø ! " õ $ % & ( ) = ?
::: @ 1 2 3 4 5 6 7 8 9 0 á
::: Q W E R T Z U I O P š *
::: q w e r t z u i o p +
::: A S D F G H J K L ™ '
::: a s d f g h j k l ” „ #
::: Y X C V B N M _
::: y x c v b n m , . -
:::: Achtung : das ø Grad-Zeichen wird zum @ At-Zeichen
:: Ersetzungstabelle x=xp, v=7
:: CMD Tast 7 OUT XP
:: -----------|--------|---
:: ^ ^ ` ^ nicht empfohlen
:: ø ° ~ ^
:: " " @ "
:: õ § # X
:: $ $ $ X
:: % % % X
:: & & ^ &
:: / / & X
:: ( ( * X
:: ) ) ( X
:: = = ) X
:: á ß - X
:: ´ ´ = X
:: ? ? _ X
:: ü [ X
:: + + ] X
:: ” ö ; X
:: „ ä ' X
:: # # \ X
:: , , , X
:: . . . X
:: š Ü {
:: * * }
:: - - /
:: ™ Ö :
:: Ž Ä "
:: _ _ ?
:: > > \
::v ~ ø
:::x ^ @
::v @ "
::v # õ
::v ^ &
::v * (
::v ( )
::v ) =
::v _ ?
::v - á
::v & /
::v ] +
::v } *
::v : ™
::v ; ”
::v " Ž
::v ' „
::v \ #
::v { š
::v [
::v / -
::v ? _
::v z y
::v Z Y
::v y z
::v Y Z