[SOLVED]check if foldername is same as a line in a file
Posted: 25 Apr 2009 11:50
Batch:
Check if the folder name the batch file is in
is the same as in server.cfg
The line in server.cfg:
"port xxxx" - xxxx = port
Foldername:
"Server xxxx" - xxxx = port
Filedir:
server.cfg => D:\Hosting\Server xxxx\server.cfg
folder => D:\Hosting\Server xxxx\
if it dosnt match i want it to close the app
-----------------------------------------------------
this echos the current port:
in server.cfg:
now how do i get the name of the folder it run from?
-----------------------------------------------------
Solution:
Check if the folder name the batch file is in
is the same as in server.cfg
The line in server.cfg:
"port xxxx" - xxxx = port
Foldername:
"Server xxxx" - xxxx = port
Filedir:
server.cfg => D:\Hosting\Server xxxx\server.cfg
folder => D:\Hosting\Server xxxx\
if it dosnt match i want it to close the app
-----------------------------------------------------
this echos the current port:
Code: Select all
@echo off
FOR /F "tokens=1,2" %%A IN (server.cfg) do (
if %%A==port (
echo %%B
)
)
in server.cfg:
Code: Select all
echo Executing Server Config...
lanmode 0
rcon_password change
maxplayers 32
port 7734
hostname Unnamed 0.2X Server
gamemode0 lvdm 1
filterscripts adminspec vactions anticrash
announce 1
query 1
weburl www.sa-mp.com
anticheat 0
now how do i get the name of the folder it run from?
-----------------------------------------------------
Solution:
Code: Select all
FOR /F "tokens=1,2" %%A IN (server.cfg) do (
if %%A==port (
FOR /F "tokens=2 delims=\\" %%C IN ("%~p0") do (
FOR /F "tokens=2" %%D IN ("%%C") do (
if not %%B==%%D exit
)
)
)
)