cmd - Get and use current folder name inside a batch file -
cmd - Get and use current folder name inside a batch file -
on server have root folder several 100 other folders named %computername% within (created respective computers using mkdir).
these %computername% folders contain bat file must unique folder (the %computername%). bat file consist of number of commands remote administration, example:
schtasks /run /s %computername% /tn "task"
is possible create bat file automatically grab folder's name (the %computername%) without having manually alter it, , utilize in specified commands above example.
use cd
command along for
retrieve current path, output folder name , ping it.
test.bat:
@echo off /f %%i in ('cd') set address=%%~nxi ping %address%
result:
c:\users\aybe\127.0.0.1>test.bat pinging 127.0.0.1 32 bytes of data: reply 127.0.0.1: bytes=32 time<1ms ttl=128 reply 127.0.0.1: bytes=32 time<1ms ttl=128 reply 127.0.0.1: bytes=32 time<1ms ttl=128 reply 127.0.0.1: bytes=32 time<1ms ttl=128 ping statistics 127.0.0.1: packets: sent = 4, received = 4, lost = 0 (0% loss), approximate round trip times in milli-seconds: minimum = 0ms, maximum = 0ms, average = 0ms c:\users\aybe\127.0.0.1>
another example:
c:\users\aybe\yahoo.com>test pinging yahoo.com [98.139.183.24] 32 bytes of data: reply 98.139.183.24: bytes=32 time=116ms ttl=48 reply 98.139.183.24: bytes=32 time=120ms ttl=48 reply 98.139.183.24: bytes=32 time=116ms ttl=48 reply 98.139.183.24: bytes=32 time=119ms ttl=48 ping statistics 98.139.183.24: packets: sent = 4, received = 4, lost = 0 (0% loss), approximate round trip times in milli-seconds: minimum = 116ms, maximum = 120ms, average = 117ms c:\users\aybe\yahoo.com>
batch-file cmd folder
Comments
Post a Comment