I am trying to write a batch that will copy the names of the profile folders to a txt file, then take each line (profile) and query ad with it. the two problems I seem to be having are:
it says there is a syntax error in the way I wrote my for loop
if I break it down for debugging, the loop seems to just set the variable over and over, then use the final value only to perform the commands in the subscripts
#echo off
#setlocal enabledelayedexpansion
pushd "c:\documents and settings"
mkdir c:\pulls
copy \\mint\testfolder\forfiles.exe c:\pulls\
copy \\mint\testfolder\psexec.exe c:\pulls\
rem call \\mint\testfolder\copy.bat c:\pulls\
set queryid=
set checkid=
rem finds all profiles that have been logged into in the last 18 months
c:\pulls\forfiles.exe /p "c:\documents and settings\" /d -540 /c "cmd /c if #ISdir==true deltree #isdir"
dir/b > "c:\documents and settings\profiles.txt"
%queryid% > "c:\documents and settings\tmp.txt"
rem active directory query
:adquery
for /f "tokens=*" %%n IN ("c:\documents and settings\profiles.txt") do (
set queryid=%%n
call :sub
)
goto :end
:sub
c:\pulls\psexec.exe \\computer-u domain\user -p password dsquery user -name %queryid% > "c:\documents and settings\tmp.txt"
set /p checkid= < "c:\documents and settings\tmp.txt"
del "c:\documents and settings\tmp.txt"
::checks to see if variable is an empty string
if [!%checkid%==!] goto :process1
if [%checkid%==] %queryid% >> c:\documents and settings\final.txt
goto :eof
:process1
c:\pulls\psexec.exe \\computer -u domain\user -p password dsquery user -name %queryid% -desc *termed* > "c:\documents and settings\tmp.txt"
set /p checkid= < "c:\documents and settings\tmp.txt"
del "c:\documents and settings\tmp.txt"
::checks to see if variable is an empty string
if [!%checkid%==!] goto :amending
if [%checkid%==] goto :process2
goto :eof
:process2
c:\pulls\psexec.exe \\computer -u domain\user -p password dsquery user -name %queryid% -disabled > "c:\documents and settings\tmp.txt"
set /p checkid= < "c:\documents and settings\tmp.txt"
del "c:\documents and settings\tmp.txt"
::checks to see if variable is an empty string
if [!%checkid%==!] goto :amending
goto :eof
:amending
%checkid% >> "c:\documents and settings\final.txt"
goto :eof
:end
notepad.exe "c:\documents and settings\final.txt"
del c:\pulls /y
del "c:\documents and settings\profiles.txt"
del "c:\documents and settings\final.txt"
rem copies selected profiles
rem c:\pulls\copy.bat
I haven't traced your entire logic to see if you have any other problems. But I have identified the problem with your FOR /F loop.
You are trying to read a file, but your IN() clause is double quoted, so it is interpreted as a string instead of a file name. (Type FOR /? for help on FOR command). You want to use double quotes because your path includes spaces, but you need it to be interpreted as a file name - that is what the USEBACKQ option is for!
for /f "usebackq tokens=*" %%n IN ("c:\documents and settings\profiles.txt") do ...
Related
hope someone can help resovle the issue I'm having.
The script asks user to provide old serial number and PC location than searches a CSV file for the SN and copies the row to a text file. Once the row is in the text file is pulls the SN and Hostname and set them into 2 variables ( the actual CSV has 10 columns). The 2 variables are later passed to a log file.
Problem I have is that if the user provided SN is not in the CSV it does not get recorded, which is needed.
Been reading over google searches and tried several different but still have same issue with losing SNs not found.
Of all the IF statements this one has worked in the pass... well I think it did.
If [%aHostname%]==[] (set oSerial=%icomputerSN%)
So the question I have is how do I get the script to hold the user provided variable if the variable is not in the CSV file?
sitepacket.svc
Serial # Host Name
2UA6492B71 0DC4A3E551DC2
MXL8361932 010E7C6B23577
MXL8321WBS 010E7C6B269C1
MXL8382H8G 0F43909049EF6
MXL8321VQ4 010E7C6B27034
MXL8331GNZ 010E7C6B7407D
MXL8331GMY 010E7C6B73961
MXL8331GPP 010E7C6B74021
MXL8331G26 010E7C6B739EF
MXL8321WFK 010E7C6B26A6B
MXL8331G1Q 010E7C6B73CF6
MXL8331GPN 010E7C6B7400C
MXL8331G3M 010E7C6B73CF7
MXL8321WBL 010E7C6B269B9
MXL8331G34 010E7C6B73D26
Script
#echo off
setlocal enabledelayedexpansion
set "au=TestRUN"
set "InstLog=%~dp0\AU%au%.csv"
net session >nul 2>&1
REM :: Get New workstations IP and set in var
set "ip="
for /f "tokens=2 delims=:" %%a in ('ipconfig ^| findstr /c:"IPv4 Address"') do set ip=%%a
:LogFileCheck
if exist %InstLog% goto :GetSN else
echo Location,Old_SN,Old_Host,Replaced_By,New_PC_IP,New_Serial,New_Host > %InstLog%
goto :GetSN
REM # Input field for tech to provide Old SN and old workstation location.
:GetSN
Echo What is the old computer serial number?
set /p icomputerSN=
Echo What is the location and location number of workstation?
set /p PcLoc=
findstr /i "%icomputerSN%" "%~dp0\Sitepacket.csv" > "%~dp0\oldsystems.txt"
FOR /F "usebackq tokens=1-9 delims=," %%a in ("%~dp0\oldsystems.txt") DO (
set aSerial=%%a
set aHostname=%%b
If [%aHostname%]==[] (set oSerial=%icomputerSN%)
)
for /f "skip=1 tokens=*" %%C in ('wmic bios get serialnumber') do if not defined serial set serial=%%C
set nserial=%serial: =%
for /f "skip=1 delims=" %%A in (
'wmic computersystem get name'
) do for /f "delims=" %%B in ("%%A") do set "nHost=%%A"
set "output=%PcLoc%,%oserial%,%oHostname%,Replace with,%nserial%,%nHost%,%IP%"
echo %output% >> %InstLog%
I am making a simple text game. Everything works fine until it gets to the if statement. I do not know what i am doing wrong.
#echo off
title Text Adventures
echo "What is your name?"
set /p name=
echo "That was a bad crash. Are you hurt, %name%?"
echo.
echo Y/N
set /p answer=
if %answer% equ y goto hurt
:hurt
echo.
echo "I see. That's a gnarly gash you've got there!"
Here I have re-written this to be in a form that uses Functions and uses the suggestions I provided to the original post as comments.
You know I assumed incorrectly that you had a purpose to using the labels, but given the way the question has give I think you would do well to not bother with them.
Here is a no-labels version:
#(SETLOCAL
echo off
title Text Adventures
)
CALL :Main
( ENDLOCAL
ECHO. The Script Ended!
PAUSE
EXIT /B
)
:Main
set /p "name=What is Your Name?"
ECHO.
CHOICE /M "That was a bad crash. Are you hurt, %name%?"
If %ERRORLEVEL% equ 1 (
echo.
echo "I see. That's a gnarly gash you've got there!"
) ELSE (
echo.
echo "Oh Good!"
)
PAUSE
GOTO :EOF
Here is the labels version. (I removed the comments explaining how it works and why the code is there so it isn't so cluttered for you.)
#(SETLOCAL
echo off
title Text Adventures
)
CALL :Main
( ENDLOCAL
ECHO. The Script Ended!
PAUSE
EXIT /B
)
:Main
set /p "name=What is Your Name?"
ECHO.
CHOICE /M "That was a bad crash. Are you hurt, %name%?"
If %ERRORLEVEL% equ 1 (
CALL :Hurt
) ELSE (
CALL :NotHurt
)
PAUSE
GOTO :EOF
:Hurt
echo.
echo "I see. That's a gnarly gash you've got there!"
GOTO :EOF
:NotHurt
echo.
echo "Oh Good!"
GOTO :EOF
For this sort of thing I prefer by far using choice, and frequently use my menu macro that returns the selected option as a string in the variable option
below is a shell script that demonstrates the usage of a few macro's I frequently use.
#ECHO Off & Goto :main
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: * Functions * :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:+------------------------------------------------------------------------------------------------+:
:ColorString
(For %%C in (%~1)Do Set "rv=!rV!%/E%!#A!m%%~C%/E%0m"& Set /A "#A+=1"& IF "!#A!"=="37" (Set #A=31))
Exit /B 0
:+------------------------------------------------------------------------------------------------+:
:ColorMenu
rem Set /A "RR=!random! %%195 + 60","GG=!random! %%195 + 60","BB=!random! %%195 + 60"
rem Set "%~1=%/E%38;2;!RR!;!GG!;!BB!m!%~1!%/E%0m"
Set "rV="& IF "!#A!"=="" (Set #A=32)
(For %%C in ("!%~1!")Do Set "rv=!rV!%/E%!#A!m%%~C%/E%0m"& Set /A "#A+=1"& IF "!#A!"=="37" (Set #A=31)) & Set "%~1=!rV!"
Exit /B 0
:+------------------------------------------------------------------------------------------------+:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
:main * Environment Definition * :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Rem /* ensure correct environment for macro definitions */
Endlocal & Setlocal DISABLEdelayedexpansion
:+------------------------------------------------------------------------------------------------+:
For /F %%a in ('echo prompt $E ^| cmd')do (Set "/E=%%a[")
:+------------------------------------------------------------------------------------------------+:
Set "ChoList=0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Set "ColLETTERS=Set "Rv="& Set "#A=31" & (For %%A in ("$Str")Do Set "Word=%%~A" & For %%B In (0 1 2 3 4 5 6 7 8 9 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 Set "Word=!Word:%%~B=%%~B !") & (Call :ColorString "!Word!" & Echo/!rV!)"
Set "ColWORD/S=Set "#A=35"& Set "MSG=$Str" & For %%G in ("!MSG!")Do (For %%v in (%%~G)Do (Set "Rv="&Call :Colorstring "%%~v"& For %%x in (!Rv!)Do (Set "MSG=!MSG:%%~v=%/E%0m%%~x!")))&Echo/!MSG!"
Set "List/D/V=Set "#$L=0"&Set "$$L="&For %%n in (1 2)Do if %%n==2 (For %%G in (!$L!)Do (Set "%%~G" > Nul &Set /A "#$L+=1"))Else Set $L="
Set "Menu=For %%n in (1 2)Do if %%n==2 (!DIV!&Set "CH#=0"&(Set "CHCS="&For %%G in (!Options!)Do For %%i in (!CH#!)Do (Set "CHCS=!CHCS!!ChoList:~%%i,1!"&Set "Opt[!ChoList:~%%i,1!]=%%~G"& Set "Opt=%%~G" &Call :ColorMenu Opt &<Nul Set /P "=[!ChoList:~%%i,1!] !Opt!"&Set /A "CH#+=1"&Echo/))&!DIV!& For /F "Delims=" %%o in ('Choice /N /C:!CHCS!')Do (Set "OPTION=!Opt[%%o]!"))Else Set Options="
Set "ColLINE=For %%n in (1 2)Do if %%n==2 (Echo/!$C!!$Str!%/E%0m)Else Set $Str="
:+------------------------------------------------------------------------------------------------+:
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
::: * Script Body * :::
::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Setlocal EnableDelayedExpansion
for /F "usebackq tokens=2* delims=: " %%W in (`mode con ^| findstr Columns`) do Set "Console_Width=%%%W"
Set "DIV="&For /L %%i in (2 1 %Console_Width%)Do Set "DIV=!DIV!-"
Set "DIV=Echo/%/E%33m!DIV!%/E%0m"
%List/D/V:$L=Colors%"Red=%/E%31m" "Yellow=%/E%33m" "Green=%/E%32m" "Blue=%/E%34m" "Purple=%/E%35m" "Cyan=%/E%36m" "White=%/E%37m" "Gray=%/E%90m" "Pink=%/E%91m" "Beige=%/E%93m" "Aqua=%/E%94m" "Magenta=%/E%95m" "Teal=%/E%96m" "Off=%/E%0m" "Black=%/E%30m"
%List/D/V:$L=Actions%"Buy a house=Did you win the lotto" "Go for a drive=Start your engines" "Walk on the wild side=Get mauled by a lion" "Run a mile=Fit yet" "flee the realm=fall down a hole" "battle trolls=A losing battle" "puzzle a conundrum=Enigma's Stigmatised" "solve 42=life is meaningless"
%ColLETTERS:$Str=Welcome.%
%ColWORD/S:$Str=Hello there my friend^! How are you today.%
%ColLINE:$C=Teal%What a world we live in^^!
%Menu%"Buy a house" "Go for a drive" "Walk on the wild side" "Run a mile" "flee the realm" "battle trolls" "puzzle a conundrum" "solve 42"
For %%G in ("!Option!")Do Echo/!%%~G!
The menu macro builds a list of choices for each argument it's supplied, using substring modification to iterate over a 36 character choice list to build the final choice options - meaning support for 36 menu options.
Update
An additional example has been added to show a way to use the selection to display output or take actions without requiring conditional testing. Using the List/D/V macro to define values to options, a selected OPTION can be expanded directly. In the example, it's just to display output, however values can be assigned containing simple commands like Set, Goto or call to perform specific actions for the chosen menu option.
I forgot to add pause
#echo off
title Text Adventures
echo "What is your name?"
set /p name=
echo "That was a bad crash. Are you hurt, %name%?"
echo.
echo Y/N
set /p answer=
if %answer% equ y goto hurt
:hurt
echo.
echo "I see. That's a gnarly gash you've got there!"
pause
I was trying to create a scrollable list for a batch file using the method found here: Scrollable Lists in .bat Files
Credit to https://stackoverflow.com/users/778560/aacini
One I tried adding back in my code for my regular batch a few lines at a time, I noticed that the solution doesn't work when I use WMIC. What is the reason for this and is there an easy solution? You can run the below code and then un-comment the WMIC line and see it will not work anymore.
Edit: I am using Windows 7
Thanks!
#if (#CodeSection == #Batch) #then
#echo off
setlocal EnableDelayedExpansion
color F0
::FOR /F "tokens=2 delims==" %%A IN ('WMIC csproduct GET Name /VALUE ^| FIND /I "Name="') DO SET machine=%%A
Echo Reset or Continue
Set MenuOptions=RESET Continue
call :ShowMenu
pause
exit
:ShowMenu
set numOpts=0
for %%a in (%MenuOptions%) do (
set /A numOpts+=1
set "option[!numOpts!]=%%a"
)
rem Clear previous doskey history
doskey /REINSTALL
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~F0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~F0"
set /P "MenuSelected=Option Selected: "
echo/
#end
var wshShell = WScript.CreateObject("WScript.Shell"),
envVar = wshShell.Environment("Process"),
numOpts = parseInt(envVar("numOpts"));
if ( WScript.Arguments.Length ) {
// Enter menu options
for ( var i=1; i <= numOpts; i++ ) {
wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
}
} else {
// Enter a F7 to open the menu
wshShell.SendKeys("{F7}");
}
SendKeys Method sends one or more keystrokes to the active window. Unfortunately, Sendkeys() sometimes fails usually due to focus or timing, both troublesome and difficult to solve problems. I tried pause and timeout, tried WshShell.AppActivate in various combinations, all without success…
Finally, I found culprit in clearing previous doskey history via doskey /REINSTALL command: it installs a new copy of doskey. I can recommend more intuitive (and less invasive) method to clear the doskey command history buffer:
doskey /ListSize=0
doskey /ListSize=50
Bonus: FOR loops explanation.
outer %%A loop to retrieve the name property;
inner %%a loop to remove the ending carriage return in the value returned: wmic behaviour: each output line ends with 0x0D0D0A (<CR><CR><LF>) instead of common 0x0D0A (<CR><LF>).
Credit: Dave Benham's WMIC and FOR /F: A fix for the trailing <CR> problem
Working script (Windows 8.1 64 bit):
#if (#CodeSection == #Batch) #then
#echo OFF
setlocal EnableDelayedExpansion
REM color F0
FOR /F "tokens=2 delims==" %%A IN ('
WMIC csproduct GET Name /VALUE ^| FIND /I "Name="
') DO FOR %%a in ("%%~A") DO SET "_machine=%%~a"
Echo Reset or Continue %_machine%
Set "MenuOptions=%_machine% RESET Continue" expanded merely for debugging purposes
call :ShowMenu
REM pause
exit /B
:ShowMenu
set numOpts=0
for %%a in (%MenuOptions%) do (
set /A numOpts+=1
set "option[!numOpts!]=%%a"
)
rem Clear previous doskey history
REM this causes problems: doskey /REINSTALL
doskey /ListSize=0
doskey /ListSize=50
rem Fill doskey history with menu options
cscript //nologo /E:JScript "%~F0" EnterOpts
for /L %%i in (1,1,%numOpts%) do set /P "var="
rem Send a F7 key to open the selection menu
cscript //nologo /E:JScript "%~F0"
set /P "MenuSelected=Option Selected: "
echo/
goto :eof
#end
var wshShell = WScript.CreateObject("WScript.Shell"),
envVar = wshShell.Environment("Process"),
numOpts = parseInt(envVar("numOpts"));
if ( WScript.Arguments.Length ) {
// Enter menu options
for ( var i=1; i <= numOpts; i++ ) {
wshShell.SendKeys(envVar("option["+i+"]")+"{ENTER}");
}
} else {
// Enter a F7 to open the menu
wshShell.SendKeys("{F7}");
}
I am looking to get a batch file that displays a list of subfolders inside a directory and allows the user to make a selection from that list of folders. When a selection has been made it should then display the contents of that folder and allow the use to make a selection. COuld anyone help with this?
Regards
John.
Example: List all folders under C:\ECU which could be ECU1, ECU2, and ECU3. Say ECU1 is selected the batch file then displays amy folders inside this e.g under ECU1 there are folders: EU1, EU2 and EU3.
I have this so far
#ECHO
setlocal enabledelayedexpansion
set Index=1
for /d %%D in (C:\ECU*) do (
set "Subfolders[!Index!]=%%D"
set /a Index+=1
)
set /a UBound=Index-1
setlocal enabledelayedexpansion
for /l %%i in (1,1,%UBound%) do echo %%i. !Subfolders[%%i]!
:choiceloop
set /p Choice=Your choice:
if "%Choice%"=="" goto chioceloop
if %Choice% LSS 1 goto choiceloop
if %Choice% GTR %UBound% goto choiceloop
set Subfolder=!Subfolders[%Choice%]!
This should work, the output isn't pretty but basically it just uses the dir command to output the folders in the directory. I would suggest reading the documentation on the dir command to get it to do exactly what you want.
#echo off
set "dir=%cd%"
:loop
echo ---Folders
dir /b /a:d %dir%
echo ---
set /p "folder=Enter a folder from the list: "
if not exist %folder% echo Not a valid folder & goto :loop
set "dir=%dir%\%folder%"
echo ---Subfolders
dir /b /a:d %dir%
echo ---
pause
I need to deploy a batch update to hundreds of services via our Control Panel, and need to replace a sub-string in a specific file when doing so. How can I use a batch file to change the following and rewrite it to the same file rather than a new file?
hostName = "Server UK (Public/Veteran) 116621";
to
hostName = "Server UK (Public/Veteran) 224421";
Here is another way to do it with pure batch. This does write to another file but then moves it without prompting, overwriting the original with the changes.
#echo off
setlocal enabledelayedexpansion
(for /f "tokens=*" %%f in (file.cfg) do if not "%%f"=="" (
set "line=%%f"
set "line=!line:116621=224421!"
echo(!line!
)) > tmp.cfg
Move /y tmp.cfg file.cfg
And here is a way with a Hybrid VBS/Batch
#echo off
setlocal
call :FindReplace "116621" "224421" file.cfg
exit /b
:FindReplace <findstr> <replstr> <file>
set tmp="%temp%\tmp.txt"
If not exist %temp%\_.vbs call :MakeReplace
for /f "tokens=*" %%a in ('dir "%3" /s /b /a-d /on') do (
for /f "usebackq" %%b in (`Findstr /mic:"%~1" "%%a"`) do (
echo(&Echo Replacing "%~1" with "%~2" in file %%~nxa
<%%a cscript //nologo %temp%\_.vbs "%~1" "%~2">%tmp%
if exist %tmp% move /Y %tmp% "%%~dpnxa">nul
)
)
del %temp%\_.vbs
exit /b
:MakeReplace
>%temp%\_.vbs echo with Wscript
>>%temp%\_.vbs echo set args=.arguments
>>%temp%\_.vbs echo .StdOut.Write _
>>%temp%\_.vbs echo Replace(.StdIn.ReadAll,args(0),args(1),1,-1,1)
>>%temp%\_.vbs echo end with
just try sed for Windows
for %%a in (*.txt) do sed -ri.bak "s#hostName = \"Server UK \(Public/Veteran\) 116621\"#hostName = \"Server UK (Public/Veteran) 224421\"#g" "%%~a"
You can use this routine to replace a string with another string in a file, saving in a separate file or overwriting the original, just past the fourth parameter to save it in a separate file, otherwise, do not pass the parameter and will be replaced with the new content.
#echo off
#break off
#title Replace substring in text file with a batch script - D3F4ULT
#color 0a
#cls
:: Routine to replace an input string by a string output in the contents of a file.
setlocal EnableDelayedExpansion
REM Examples
REM call:replace-string-file-from-to "config.cfg" "116621" "224421"
REM call:replace-string-file-from-to "config.cfg" "116621" "224421" "config.cfg"
REM call:replace-string-file-from-to "config.cfg" "116621" "224421" "configuration.dat"
REM call:replace-string-file-from-to "%UserProfile%\Downloads\config.cfg" "116621" "224421" "%UserProfile%\Downloads\configuration.dat"
REM Calling Routine
call:replace-string-file-from-to "config.cfg" "116621" "224421"
exit
:replace-string-file-from-to
:: %~1 = File [In] [Mandatory]
:: %~2 = From [In] [Mandatory]
:: %~3 = To [In] [Mandatory]
:: %~4 = Out [Out] [Optional]
REM Mandatory Parameters
if "%~1" EQU "" echo Error %%~1 not defined&&echo.&&ping -n 4 localhost>nul&&exit /B 1
if "%~2" EQU "" echo Error %%~2 not defined&&echo.&&ping -n 4 localhost>nul&&exit /B 1
if "%~3" EQU "" echo Error %%~3 not defined&&echo.&&ping -n 4 localhost>nul&&exit /B 1
if exist "%~dpnx1" (
set "INPUT_FILE_LOCATION=%~dpnx1"
cd /D "%~dp1"
) else if exist "%~dp0\%~nx1" (
set "INPUT_FILE_LOCATION=%~dp0%~nx1"
cd /D "%~dp0"
) else if exist "!CD!\%~nx1" (
set "INPUT_FILE_LOCATION=!CD!\%~nx1"
cd /D "!CD!"
)
if not defined INPUT_FILE_LOCATION (
echo ERROR
echo.
echo File not found = '%~nx1'
echo.
echo Exiting...
echo.
ping -n 8 localhost>nul
exit /B 1
)
set "INPUT_FILE_FOLDER=%~dp1"
set "INPUT_FILE_NAME=%~n1"
set "INPUT_FILE_EXTENSION=%~x1"
if "%~4" EQU "" (
set "OUTPUT_FILE_LOCATION=!INPUT_FILE_FOLDER!!INPUT_FILE_NAME!__new__!INPUT_FILE_EXTENSION!"
set "INOUT_DEL_MOVE=true"
) else if "%~dpnx1" EQU "%~dpnx4" (
set "OUTPUT_FILE_LOCATION=!INPUT_FILE_FOLDER!!INPUT_FILE_NAME!__new__!INPUT_FILE_EXTENSION!"
set "INOUT_DEL_MOVE=true"
) else (
set "OUTPUT_FILE_FOLDER=%~dp4"
set "OUTPUT_FILE_NAME=%~n4"
set "OUTPUT_FILE_EXTENSION=%~x4"
set "OUTPUT_FILE_LOCATION=!OUTPUT_FILE_FOLDER!!OUTPUT_FILE_NAME!!OUTPUT_FILE_EXTENSION!"
)
if exist "!OUTPUT_FILE_LOCATION!" (
del /f /q "!OUTPUT_FILE_LOCATION!">nul
)
for /F "usebackq tokens=*" %%A in ( "!INPUT_FILE_LOCATION!" ) do (
set "string=%%~A"
set "string=!string:%~2=%~3!"
echo !string!>>"!OUTPUT_FILE_LOCATION!"
)
if defined INOUT_DEL_MOVE (
if exist "!INPUT_FILE_LOCATION!" (
del /f /q "!INPUT_FILE_LOCATION!">nul
)
if exist "!OUTPUT_FILE_LOCATION!" (
move /y "!OUTPUT_FILE_LOCATION!" "!INPUT_FILE_LOCATION!">nul
)
)
goto:eof