Cant seem to find a way to encode a url using a batch so i remember to make a replace.
The problem is that the url encode uses % and i think thats the problem for my code not to be working.
ex: SET varr=!varr:#=%23!
Anyone have an idea how to do this?
Full code bellow (without some of the url encode because of stack lenght issues)
#ECHO OFF
Setlocal EnableDelayedExpansion
SET varr={"temRazs":{"es":{"ted":[],"items":[{"cod":"1234567","nam":"patrick","where":"ggf","tip":"P",false,"shared":false,"verid":"1064.0ada83b2-3a3f-46a3-95b7-35b8c9ed8f24","className":"myclassname"}}}
SET varr=!varr:"=%22!
SET varr=!varr:#=%23!
SET varr=!varr:$=%24!
SET varr=!varr:%=%25!
SET varr=!varr:&=%26!
SET varr=!varr:'=%27!
SET varr=!varr:(=%28!
SET varr=!varr:)=%29!
SET varr=!varr:*=%2A!
SET varr=!varr:+=%2B!
SET varr=!varr:,=%2C!
SET varr=!varr:-=%2D!
SET varr=!varr:.=%2E!
SET varr=!varr:/=%2F!
SET varr=!varr:0=%30!
SET varr=!varr:1=%31!
SET varr=!varr:9=%39!
SET varr=!varr::=%3A!
SET varr=!varr:;=%3B!
SET varr=!varr:<=%3C!
SET varr=!varr:==%3D!
SET varr=!varr:>=%3E!
SET varr=!varr:?=%3F!
SET varr=!varr:#=%40!
SET varr=!varr:A=%41!
SET varr=!varr:[=%5B!
SET varr=!varr:\=%5C!
SET varr=!varr:]=%5D!
SET varr=!varr:^=%5E!
SET varr=!varr:_=%5F!
SET varr=!varr:`=%60!
SET varr=!varr:z=%7A!
SET varr=!varr:{=%7B!
SET varr=!varr:|=%7C!
SET varr=!varr:}=%7D!
SET varr=!varr:~=%7E!
SET varr=!varr:,=%B4!
SET varr=!varr:µ=%B5!
SET varr=!varr:»=%BB!
SET varr=!varr:¼=%BC!
SET varr=!varr:½=%BD!
SET varr=!varr:¿=%BF!
SET varr=!varr:À=%C0!
SET varr=!varr:Á=%C1!
SET varr=!varr:Â=%C2!
SET varr=!varr:Ã=%C3!
SET varr=!varr:Ä=%C4!
SET varr=!varr:Å=%C5!
SET varr=!varr:Æ=%C6!
SET varr=!varr:Ç=%C7!
SET varr=!varr:È=%C8!
SET varr=!varr:É=%C9!
SET varr=!varr:ô=%F4!
SET varr=!varr:õ=%F5!
SET varr=!varr:ö=%F6!
SET varr=!varr:÷=%F7!
echo 1
pause
set urll=!varr!)
echo %urll%
Pause
Thanks
Related
So I map a drive to T \server01\tfolder
I need a script which does the following
If T is mapped to \server01\tfolder then map it to server02\tolder. But if drive is mapped to \server02\tfolder then map it to \server01\tfolder
I am using an else switch but already but can't for the life of me work out how I get it to confirm which its being mapped to already and then map it to the alternate.
Any ideas?
for /f "tokens=2" %%a in ('net use t: ^|find "\\"') do set "current=%%a"
if "%current%" == "\\server01\tfolder" (
set "new=\\server02\tfolder"
) else (
set "new=\\server01\tfolder"
)
echo switching from %current% to %new%
I am trying to make a batch file that opens multiple urls via wget and then extracts pictures from them based on a key word in the html. The problem I am having is the way the url is written the batch seems to think it is a list of commands that do not exist. the url is formatted as such http://gatherer.wizards.com/Pages/Search/Default.aspx?page=2&output=spoiler&method=visual&action=advanced&set=%5B%22ORI%22%5D
I need to get the url to be recognized as a url and have a variable to change one part of the url at the point that says ORI.
This is how the variable is being set I am new to arrays so I have probably done this the hard way.
#echo off
setlocal EnableDelayedExpansion
set array[0]=ARN
set array[1]=ATQ
set array[2]=LEG
set array[3]=DRK
set array[4]=FEM
set array[5]=HML
set array[6]=ICE
set array[7]=ALL
set array[8]=CSP
set array[9]=MIR
set array[10]=VIS
set array[11]=WTH
set array[12]=TMP
set array[13]=STH
set array[14]=EXO
set array[15]=USG
set array[16]=ULG
set array[17]=UDS
set array[18]=MMQ
set array[19]=NEM
set array[20]=PCY
set array[21]=INV
set array[22]=PLS
set array[23]=APC
set array[24]=ODY
set array[25]=TOR
set array[26]=JUD
set array[27]=ONS
set array[28]=LGN
set array[29]=SCG
set array[30]=MRD
set array[31]=DST
set array[32]=5DN
set array[33]=CHK
set array[34]=BOK
set array[35]=SOK
set array[36]=RAV
set array[37]=GPT
set array[38]=DIS
set array[39]=TSP
set array[40]=TSB
set array[41]=PLC
set array[42]=FUT
set array[43]=LRW
set array[44]=MOR
set array[45]=SHM
set array[46]=EVE
set array[47]=ALA
set array[48]=CON
set array[49]=ARB
set array[50]=ZEN
set array[51]=WWK
set array[52]=ROE
set array[53]=SOM
set array[54]=MBS
set array[55]=NPH
set array[56]=ISD
set array[57]=DKA
set array[58]=AVR
set array[59]=RTR
set array[60]=GTC
set array[61]=DGM
set array[62]=THS
set array[63]=BNG
set array[64]=JOU
set array[65]=KTK
set array[66]=FRF
set array[67]=DTK
set array[68]=BFZ
set array[69]=OGW
set array[70]=SOI
set array[71]=EMN
set array[72]=CHR
set array[73]=ATH
set array[74]=BRB
set array[75]=BTD
set array[76]=DKM
set array[77]=DPA
set array[78]=EMA
set array[79]=EVG
set array[80]=DD2
set array[81]=DDC
set array[82]=DDD
set array[83]=DDE
set array[84]=DDF
set array[85]=DDG
set array[86]=DDH
set array[87]=DDI
set array[88]=DDJ
set array[89]=DDK
set array[90]=DDL
set array[91]=DDM
set array[92]=DDN
set array[93]=DD3
set array[94]=DDO
set array[95]=DDP
set array[96]=DDQ
set array[97]=DDR
set array[98]=DDS
set array[99]=DRB
set array[100]=V09
set array[101]=V10
set array[102]=V11
set array[103]=V12
set array[104]=V13
set array[105]=V14
set array[106]=V15
set array[107]=V16
set array[108]=H09
set array[109]=PD2
set array[110]=PD3
set array[111]=MMA
set array[112]=MM2
set array[113]=MM3
set array[114]=MD1
set array[115]=HOP
set array[116]=PC2
set array[117]=PCA
set array[118]=ARC
set array[119]=CMD
set array[120]=CMA
set array[121]=C13
set array[122]=C14
set array[123]=C15
set array[124]=C16
set array[125]=CMA
set array[126]=CNS
set array[127]=CN2
set array[128]=POR
set array[129]=PO2
set array[130]=PTK
set array[131]=S99
set array[132]=S00
set array[133]=CED
set array[134]=UGL
set array[135]=UNH
set array[136]=LEA
set array[137]=LEB
set array[138]=2ED
set array[139]=3ED
set array[140]=4ED
set array[141]=5ED
set array[142]=6ED
set array[143]=7ED
set array[144]=8ED
set array[145]=9ED
set array[146]=10E
set array[147]=M10
set array[148]=M11
set array[149]=M12
set array[150]=M13
set array[151]=M14
set array[152]=M15
set array[153]=ORI
set n=0
:start
if NOT !n!==154 (
echo http://gatherer.wizards.com/Pages/Search/Default.aspx?page=2&output=spoiler&method=visual&action=advanced&set=%5B%22!array[%n%]!%22%5D
set /A n=n+1
goto :start
)
echo done!
I want to replace OLD with %NEW% in test.txt by using a batch file:
#echo off
set /p NEW=""
set InputFile=test.txt
find OLD
replace %NEW%
my test.txt contains various characters like ~ : ; _ .which I attribute to various solutions clapping out.
I have attempted to use BatchSubstitude.bat to achieve this but it does not "find" OLD and does not replace any text.
I have also attempted to use fart.exe but I receieve an error when trying to perform this:
find_string="OLD"
replace_string="test"
actual find_length=3
actual replace_length=4
processing \filepath\,test.txt
skipping binary file: \filepath\test.txt
The documentation for this is sparse and nothing I could google furiously would provide a solution.
The reason I am using batch for the moment is that I perform various windows CE actions such as cecopy, pdel and rapistart for windows CE deployment over activesync and batch seems to be the easiest way to to get the result that I am after - and I'm a total noob at batch.
Does anyone know how this can be achieved with batch and perhaps explain how the various functions work to achieve this?
Cheers!
Try this:
#set #a=0 /*
#echo off
set /p NEW=""
set InputFile=test.txt
cscript //nologo //E:JScript "%~F0" "%NEW%" < "%InputFile%" > output.tmp
move /Y output.tmp "%InputFile%"
#goto :EOF */
WScript.Stdout.Write(WScript.Stdin.ReadAll().replace(/OLD/g,WScript.Arguments(0)));
Do not download anything from sourceforge so better to skip fart-it.
The method in the dostips is not so robust when special characters are used (&<>|^) as it is pointed there.Here's a simple batch/jscript that will replace a content in a file (you can change the hardcoded things like file location):
0</* :
#echo off
set "file=c:\test.txt"
set "find=OLD"
set /p "replace=NEW: "
cscript /nologo /E:jscript "%~f0" %file% %find% %replace%
echo ==replaced==
exit /b */0;
var FSOObj = new ActiveXObject("Scripting.FileSystemObject");
var ARGS = WScript.Arguments;
if (ARGS.Length < 3 ) {
WScript.Echo("Wrong arguments");
WScript.Quit(1);
}
var filename=ARGS.Item(0);
var find=ARGS.Item(1);
var replace=ARGS.Item(2);
var readStream=FSOObj.OpenTextFile(filename, 1);
var content=readStream.ReadAll();
readStream.Close();
function replaceAll(find, replace, str) {
return str.replace(new RegExp(find, 'g'), replace);
}
var newConten=replaceAll(find,replace,content);
var writeStream=FSOObj.OpenTextFile(filename, 2);
writeStream.WriteLine(newConten);
writeStream.Close();
Check also this more advanced tools
FindRepl
JRepl
I am having some troubles and I hope someone can help. I have a game server that I am running on a dedicated server. I have a batch file that is currently running the server. The server needs to be restarted 4 hours after the server starts. What I am struggling with is the statements to get the batch file to run my restart batch file in 4 hours? If the batch file says run my restart batch in 4 hours my life will be saved.
here is my current batch file.
#echo off
if "%configdone%"=="1" (
GOTO :EOF
)
set configdone=0
set skbt_debug=2
set keepalive_database=1
set keepalive_bec=0
set keepalive_asm=0
set keepalive_ts=0
set keepalive_hc=0
set serverport=2302
set bindtoip=0
set serverip=118.217.115.72
set bec_flag_dsc=1
set teamspeak_port=2310
set asm_log_interval=5
set serverStartTimeout=10
set db_backup_interval=60
set use_zip_logs=1
set use_zip_backups=1
set databasebackupfolder="E:\Overpoch Server 1\Backup"
set logfilebackupfolder="C:\apps\epoch_log_backups"
set manual_timeout_length=2
set auto_timeout_length=10
set auto_restart_delay=5
set cleanWerDialogs=1
set hclaunchparams=-connect=1 -ip=199.217.115.72 -port=2312 -client -nosound -mod=#Epoch;#EpochHive;#MAS;
set armaserverexe=arma3server.exe
set hcexename=arma3serverHC.exe
set teamspeakfilename=ts3server_win64.exe
set redisexename=redis-server.exe
set becexename=bec.exe
set asmexename=ArmaServerMonitor.exe
set databasefile_name=dump.rdb
set asm_log_file=asm_performance.log
set armapath="C:\servers\epochServer"
set hcarmapath="C:\servers\epochServer"
set teamspeakpath="C:\apps\teamspeak"
set redispath="C:\servers\epochServer\DB"
set asmpath="C:\servers\epochServer"
set Battleyepath="C:\servers\epochServer\SC\BattlEye"
set LogPath="C:\servers\epochServer\SC"
set becpath="C:\servers\epochServer\BEC"
set databasefile="C:\servers\epochServer\DB\dump.rdb"
set servercfgpath="C:\servers\epochServer\SC\config.cfg"
set serverbasicpath="C:\servers\epochServer\SC\basic.cfg"
set profilepathname="SC"
set cli_username="SC"
if %bindtoip%==1 (
set ip_param= -ip=%serverip%
) else (
set ip_param=
)
set mod_string=-mod=#Epoch;#EpochHive;#MAS;
set servercommandline=%armaserverexe% "%mod_string:"=%" "-config=%servercfgpath:"=%" %ip_param% -port=%serverport% "-profiles=%profilepathname:"=%" "-cfg=%serverbasicpath:"=%" "-name=%cli_username:"=%" -autoinit
set serverAffinity=0,1,2,3,4,5,6,7
set becAffinity=0,1,2,3,4,5,6,7
set hcAffinity=0,1,2,3,4,5,6,7
set redisAffinity=2,3,4,5,6,7,0,1
set teamspeakAffinity=0,1,2,3,4,5,6,7
set asmAffinity=0,1,2,3,4,5,6,7
set serverPriority=normal
set becPriority=normal
set hcPriority=normal
set redisPriority=normal
set teamspeakPriority=normal
set asmPriority=normal
This is my restart batch
#echo off
call "C:\servers\EPOCHS~2\batch\ULTSGS~1.CMD"
cd /D %armapath%
if %skbt_debug% GTR 2 (
call :FUNC NOVAR BatchLogWrite 3__AUTO_RESTART__EVENT__INITIALIZE====================================
)
call batch_lib\lib\setauto.bat
call batch_lib\lib\stop_all.bat
goto :EOF
:FUNC
set currentDir=%CD%
cd "%armapath%/batch_lib/gbl_func"
rem %1 = return var, %2 = function, %3 = args
set returnvarname=%1
set funcname=%2
set argString=%3
set argString=%argString:__= %
set argString=%argString:"=%
set argString=%argString:(=[%
set argString=%argString:)=]%
set args=%argString%
if "%argString%"=="__=" set args=
if "%argString%"=="" (
set args=
)
set filename=%funcname%.cmd
set val1=
for /f %%I in ('%filename% "%args%"') do (
set "val1=%%I"
)
set "%1=%val1%"
cd %currentDir%
goto :EOF
Thanks for your help!
Jayson
What's wrong with just - waits 4 hours then reboots.
timeout /t 14400
shutdown /r /f /t 0
My custom defined protocol (phpfile) lets me open php-files in an editor through the browser. The only problem is, it gives the full url, that is different in each browser, i've seen:
phpfile:/[file]
phpfile:/[file]/
phpfile://[file]/
phpfile://[file]
All these need to be converted to just [file]. The problem is that I get a syntax error. What is the correct syntax?
set var=%1
if("%var:~0,9%"=="phpfile:/")
{
set url = %var:~9%
}
else
{
set url = %var:~10%
}
if(%var:-1,1% == "/")
{
url = %url:~0,-1%
}
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" url
=== Edit ===
I now have the following, but it is adding "" at the end of the url
SETLOCAL enabledelayedexpansion
set var=%1
if %var:~0,9%=="phpfile:/" (
set url = %var:~9%
) else (
set url = %var:~10%
)
if "%var:~-1%"=="\" (
set url = %url:~0,-1%"
)
if "%var:~-1%"=="/" (
set url = %url:~0,-1%"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" %url:"=%
That's because you wrote some horrible bastard between batch files and C but certainly no language that is in use anywhere.
Try the following:
setlocal enabledelayedexpansion
set "var=%~1"
if "!var:~0,9!=="phpfile:/" (
set "url=!var:~9!"
) else (
set "url=!var:~10!"
)
if "!var:-1,1!"=="/" (
set "url=!url:~0,-1!"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" "!url!"
Delayed expansion was used primarily to deal better with some characters that cause trouble in batch files. Generally though, I wonder how you would ever have expected your code to work.
There were quite a few problems in your code, this should fix things:
set var="%1"
if %var:~0,9%=="phpfile:/" (
set url="%var:~9%"
) else (
set url="%var:~10%"
)
if "%var:-1,1%"=="/" (
set url="%url:~0,-1%"
)
START "" "C:\Program Files (x86)\NuSphere\PhpED\7.0\phped.exe" url
You can check the syntax of batch file commands using help <command>. IF statements don't use curly braces, or require round brackets around the conditional statement.