autocomplete path in cmd batch - windows

Windows CMD prompt's auto-complete, (similar feature in other terminals), comes very handy sometimes when you are not sure of the right path or file name.
Bottom line is, how to use this feature in batch scripting.
Example: the script "C:\Program Files\Java\jre1.8.0_92\bin\javaw.exe" -jar post.jar
the thing here is that java version is not always the same, so it needed to be something like this
"C:\Program Files\Java\jre*\bin\javaw.exe" -jar post.jar

you can't use wildcards in the middle of a path, but you can at the end (the last element). Because you need it in between, split it up:
for /f "delims=" %%a in ('dir /b /ad /on "C:\Program Files\Java\jre*"') do set ver=%%a
set "exec=C:\Program Files\Java\%ver%\javaw.exe"
"%exec%" -jar post.jar
This will get you the path with the highest version number, if there are more than one.

Wildcards are supported by only some commands. Moreover, cmd restricts wildcards in a file path only in a path leaf i.e. in token behind last backslash…
On an unknown Windows system: if you do not have control on environment variables then you need to find a file path e.g. as follows (note the _checkPath variable assignment is changed to get reasonable output as I do not have java installed):
#ECHO OFF
SETLOCAL EnableExtensions DisableDelayedExpansion
rem assign path with a wildcard * not in path leaf
set "_checkPath=C:\Program Files\Java\jre*\bin\javaw.exe"
rem delete or comment-up next line i.e. my test data set "_checkPath=..."
set "_checkPath=%ProgramFiles%*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservr%1.exe"
set "_itemFirst="
rem previous line: delete variable; next line: show setting
set _checkPath
echo(---
rem next two lines: ensure that a wildcard * not in path leaf is not allowed
echo dir /B /S "%_checkPath%"
dir /B /S "%_checkPath%"
echo(---
rem find all files by parsing powershell output ( note proper escaping ^^^| )
for /F "usebackq tokens= 1* delims=: " %%G in (`
powershell -C Get-ChildItem '"%_checkPath%"' -Recurse ^^^| Format-List -Property FullName
`) do (
rem assign first found item
if not defined _itemFirst set "_itemFirst=%%~H"
rem assign every found item thus last found item
set "_item_Last=%%~H"
rem show every found item
echo .exe found %%~H
)
echo(---
rem show setting found
set _item
echo(---
if defined _itemFirst (
echo success: "%_checkPath%"
rem commands are merely ECHOed and (my test data) commented up
rem use found items (choose any)
rem ECHO "%_itemFirst%" -jar post.jar
rem ECHO "%_item_Last%" -jar post.jar
) else (
echo NOT FOUND "%_checkPath%"
)
Above code snippet is richly commented where necessary for better understanding. Output shows both variants:
==> D:\bat\SO\38281447.bat XXX
_checkPath=C:\Program Files*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservrXXX.exe
---
dir /B /S "C:\Program Files*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservrXXX.exe"
The filename, directory name or volume label syntax is incorrect.
---
---
Environment variable _item not defined
---
NOT FOUND "C:\Program Files*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservrXXX.exe"
==> D:\bat\SO\38281447.bat
_checkPath=C:\Program Files*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservr.exe
---
dir /B /S "C:\Program Files*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservr.exe"
The filename, directory name or volume label syntax is incorrect.
---
.exe found C:\Program Files\Microsoft SQL Server\100\LocalDB\Binn\sqlservr.exe
.exe found C:\Program Files\Microsoft SQL Server\110\LocalDB\Binn\sqlservr.exe
.exe found C:\Program Files\Microsoft SQL Server\120\LocalDB\Binn\sqlservr.exe
---
_itemFirst=C:\Program Files\Microsoft SQL Server\100\LocalDB\Binn\sqlservr.exe
_item_Last=C:\Program Files\Microsoft SQL Server\120\LocalDB\Binn\sqlservr.exe
---
success: "C:\Program Files*\Microsoft SQL Server\1*\LocalDB\Binn\sqlservr.exe"
==>

Related

Check if there are any folders in a directory

CMD. How do I check if a directory contains a folder/s (name is not specified)? Other files are ignored.
If this was in the case of any .txt file, it would kind of look like this :
if exist * .txt
How do I do it with "any" folder?
There are multiple solutions to check if a directory contains subdirectories.
In all solutions below the folder for temporary files referenced with %TEMP% is used as an example.
Solution 1 using FOR /D:
#echo off
set "FolderCount=0"
for /D %%I in ("%TEMP%\*") do set /A FolderCount+=1
if %FolderCount% == 0 (
echo Temporary files folder has no non-hidden subfolder.
) else if %FolderCount% == 1 (
echo Temporary files folder has one non-hidden subfolder.
) else (
echo Temporary files folder has %FolderCount% non-hidden subfolders.
)
pause
The problem with this solution is that FOR with option /D to search for directories matching the wildcard pattern * in specified directory for temporary files ignores the directories with hidden attribute set. For that reason the command SET with the arithmetic expression to increment the value of environment variable FolderCount by one on each each directory is not executed for a directory with hidden attribute set.
The short version of this solution without counting the folders:
#echo off
for /D %%I in ("%TEMP%\*") do goto HasFolders
echo Temporary files folder has no non-hidden subfolder.
goto EndBatch
:HasFolders
echo Temporary files folder has non-hidden subfolders.
:EndBatch
pause
The loop is exited with command GOTO on FOR has assigned first name of a non-hidden directory to the loop variable.
Solution 2 using FOR /F and DIR:
#echo off
set "FolderCount=0"
for /F "eol=| delims=" %%I in ('dir "%TEMP%" /AD /B 2^>nul') do set /A FolderCount+=1
if %FolderCount% == 0 (
echo Temporary files folder has no subfolder.
) else if %FolderCount% == 1 (
echo Temporary files folder has one subfolder.
) else (
echo Temporary files folder has %FolderCount% subfolders.
)
pause
FOR with option /F and a set enclosed in ' results in starting in background one more command process with %ComSpec% /c and the command line within ' appended as additional arguments. So executed is with Windows installed to C:\Windows:
C:\Windows\System32\cmd.exe /c dir "C:\Users\UserName\AppData\Local\Temp" /AD /B 2>nul
DIR executed by background command process searches
in specified directory for temporary files
just for directories because of option /AD (attribute directory)
with including also directories with hidden attribute set because of option /AD overrides the default /A-H (all attributes except attribute hidden)
and outputs them in bare format because of option /B which results in ignoring the standard directories . (current directory) and .. (parent directory) and printing just the directory names without path.
The output of DIR is written to handle STDOUT (standard output) of the started background command process. There is nothing output if the there is no subdirectory in the specified directory.
There is an error message output to handle STDERR (standard error) of background command process if the specified directory does not exist at all. This error message would be redirected by the command process executing the batch file to own STDERR handle and would be output in console window. For that reason 2>nul is appended to the DIR command line to suppress the error message in background command process by redirecting it from handle STDERR to device NUL.
Read the Microsoft article about Using command redirection operators for an explanation of 2>nul. The redirection operator > must be escaped with caret character ^ on FOR command line to be interpreted as literal character when Windows command interpreter processes this command line before executing command FOR which executes the embedded dir command line with using a separate command process started in background.
FOR with option /F captures the output written to handle STDOUT of started background command process and processes the output line by line after started cmd.exe terminated itself after finishing execution of internal command DIR.
Empty lines are ignored by default by FOR which do not occur here.
FOR would split up the line by default into substrings using normal space and horizontal tab character as string delimiters and would assign just first space/tab separated string to specified loop variable I. This line splitting behavior is unnecessary here and is disabled for that reason by using option delims= which defines an empty list of string delimiters.
FOR would ignore also lines on which first substring after splitting a line up into substrings starts with default end of line character ;. The line splitting behavior is already disabled, but the name of directory can start unusually with a semicolon. Such a directory name would be ignored by FOR. Therefore the option eol=| defines the vertical bar as end of line character which no directory name can have and so no directory is ignored by FOR. See also the Microsoft documentation page Naming Files, Paths, and Namespaces.
The directory name assigned to loop variable I is not really used because of FOR executes for each directory name just command SET with an arithmetic expression to increment the value of the environment variable FolderCount by one.
The environment variable FolderCount contains the number of subfolders in specified directory independent on hidden attribute.
The short version of this solution without counting the folders:
#echo off
for /F "eol=| delims=" %%I in ('dir "%TEMP%" /AD /B 2^>nul') do goto HasFolders
echo Temporary files folder has no subfolder.
goto EndBatch
:HasFolders
echo Temporary files folder has subfolders.
:EndBatch
pause
The loop is exited with command GOTO on FOR has assigned first name of a directory to the loop variable.
Solution 3 using DIR and FINDSTR:
#echo off
dir "%TEMP%" /AD /B 2>nul | %SystemRoot%\System32\findstr.exe /R "^." >nul
if errorlevel 1 (
echo Temporary files folder has no subfolder.
) else (
echo Temporary files folder has subfolders.
)
pause
The output of DIR as explained above executed by cmd.exe processing the batch file is redirected from STDOUT of command process to STDIN (standard input) of FINDSTR which searches for lines having at least one character. The found lines are all lines with a directory name output by DIR. This search result is of no real interest and therefore redirected to device NUL to suppress it.
FINDSTR exits with 1 if no string could be found and with 0 on having at least one string found. The FINDSTR exit code is assigned by Windows command processor to ERRORLEVEL which is evaluated with the IF condition.
The IF condition is true if exit value of FINDSTR assigned to ERRORLEVEL is greater or equal 1 which is the case on no directory found by DIR and so FINDSTR failed to find any line with at least one character.
This solution could be also written as one command line:
dir "%TEMP%" /AD /B 2>nul | %SystemRoot%\System32\findstr.exe /R "^." >nul && echo Temporary files folder has subfolders.|| echo Temporary files folder has no subfolder.
See single line with multiple commands using Windows batch file for an explanation of the operators && and || used here to evaluate the exit code of FINDSTR.
Additional hints:
It would be good to first check if the directory exists at all before checking if it contains any subdirectories. This can be done in all three solutions above by using first after #echo off
if not exist "%TEMP%\" (
echo Folder "%TEMP%" does not exist.
pause
exit /B
)
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
cmd /?
dir /?
echo /?
exit /?
findstr /?
for /?
goto /?
if /?
pause /?
set /?
DIR "your directory" /ad, for example DIR C:\Users /ad brings out all folders that are inside C:\Users
Displays a list of files and subdirectories in a directory.
DIR [ drive:][path][filename] [/A[[:]attributes]] [/B] [/C] [/D] [/L] [/N]
[/O[[:]sortorder]] [/P] [/Q] [/R] [/S] [/T[[:]timefield]] [/W] [/X] [/4]
[drive:][path][filename]
Specifies drive, directory, and/or files to list.
/A Displays files with specified attributes.
attributes D Directories R Read-only files
H Hidden files A Files ready for archiving
S System files I Not content indexed files
L Reparse Points
If you just want to use the cmd.exe shell console to see if there are any directories:
DIR /A:D
If you want to check for it in a .bat file script:
SET "HASDIR=false"
FOR /F "eol=| delims=" %%A IN ('DIR /B /A:D') DO (SET "HASDIR=true")
IF /I "%HASDIR%" == "true" (
REM Do things about the directories.
)
ECHO HASDIR is %HASDIR%

Reuse result of "where" command

I need to find the specific location of java 64-bit on a windows machine. I thought about using where java to find all possible locations. In the next step I would need to isolate the proper location which starts with: C:\Program Files\Java\... and then execute the command as following:
cmd /K %var% -jar %~dp0XYZ.jar
Is this the proper way to find the java path which might change over time? If yes, how can I get the path from where into a variable?
For the output of where assume this:
C:\Program Files (x86)\Common Files\Oracle\Java\javapath\java.exe
C:\Program Files\Java\jdk1.8.0_144\bin\java.exe
C:\Program Files\Java\jdk1.8.0_144\jre\bin\java.exe
It wouldn't matter if it takes second or third result, as both are 64 bit in this case. But as I can't guarantee that output, the only way to identify the 64-bit version is with C:\Program Files\Java\
The following bat script (commented for explanation) should do the trick:
#ECHO OFF
rem SETLOCAL EnableExtensions DisableDelayedExpansion
set "_flagexe64=:\Program Files\Java\"
set "_javaexe64="
for /f "delims=" %%G in ('where java.exe') do (
rem next two lines for debugging only
echo checking "%%~G"
"%%~G" -version
if not defined _javaexe64 (
set "_javaexe64=%%~G"
call :check64
)
)
rem final check
if not defined _javaexe64 (
1>&2 echo sorry, no java.exe found under "%_flagexe64%"
goto :eof
)
rem java.exe found:
echo "%_javaexe64%"
goto :eof
:check64
call set "_aux=%%_javaexe64:%_flagexe64%=%%"
if "%_aux%" == "%_javaexe64%" set "_javaexe64="
goto :eof

How to execute an application existing in each specific folder of a directory tree on a file in same folder?

I have some folders with different names. Each folder has a specific structure as listed below:
Folder1
Contents
x64
Folder1.aaxplugin
TransVST_Fixer.exe
Folder 2
Contents
x64
Folder 2.aaxplugin
TransVST_Fixer.exe
There are two files within each subfolder x64. One file has the same name as the folder two folder levels above. The other file is an .exe file whose name is the same in all folders.
Now I need to run file with file extension aaxplugin on each specific .exe file. It would be obviously very time consuming opening each and every single folder and drag & drop each file on .exe to run it on this file.
That's why I am trying to create a batch script to save some time.
I looked for solutions here on Stack Overflow. The only thing I have found so far was a user saying this: When I perform a drag & drop, the process 'fileprocessor.exe' is executed. When I try to launch this exe, though, CMD returns error ('not recognized or not batch file' stuff).
How can I do this?
UPDATE 12/22/2015
I used first a batch file with following line to copy the executable into x64 subfolder of Folder1.
for /d %%a in ("C:\Users\Davide\Desktop\test\Folder1\*") do ( copy "C:\Program Files\Sugar Bytes\TransVST\TransVST_Fixer.exe" "%%a\x64\" 2> nul )
After asking here, I tried the following script:
for /f "delims=" %%F in ('dir /b /s x64\*.aaxplugin') do "%%~dpFTransVST_Fixer.exe" "%%F"
Unfortunately, the output is as following
C:\Users\Davide\Desktop>for /F "delims=" %F in ('dir /b /s x64\*.aaxplugin') do "%~dpFTransVST_Fixer.exe" "%F"
The system cannot find the file specified.
Try the following batch code:
#echo off
setlocal EnableDelayedExpansion
for /R "%USERPROFILE%\Desktop\test" %%F in (*.aaxplugin) do (
set "FilePath=%%~dpF"
if not "!FilePath:\x64\=!" == "!FilePath!" "%ProgramFiles%\Sugar Bytes\TransVST\TransVST_Fixer.exe" "%%F"
)
endlocal
The command FOR with option/R searches recursive in all directories of directory %USERPROFILE%\Desktop\test being expanded on your machine to C:\Users\Davide\Desktop for files with file extension aaxplugin. The loop variable F contains on each loop run the name of the found file with full path without surrounding double quotes.
The drive and path of each found file is assigned to environment variable FilePath.
Next a case-sensitive string comparison is done between file path with all occurrences of string \x64\ case-insensitive removed with unmodified file path.
Referencing value of environment variable FilePath must be done here using delayed expansion because being defined and evaluated within a block defined with ( ... ). Otherwise command processor would expand %FilePath% already on parsing the entire block resulting in a syntax error on execution because string substitution is not possible as no environment variable FilePath defined above body block of FOR loop.
The strings are not equal if path of file contains a folder with name x64. This means on provided folder structure that the file is in folder x64 and not somewhere else and therefore the application is executed next from its original location to fix the found *.aaxplugin file.
The line with IF is for the folder structure example:
if not "C:\Users\Davide\Desktop\test\Folder1\Contents" == "C:\Users\Davide\Desktop\test\Folder1\Contents\x64\"
if not "C:\Users\Davide\Desktop\test\Folder 2\Contents" == "C:\Users\Davide\Desktop\test\Folder 2\Contents\x64\"
So for both *.aaxplugin files the condition is true because the compared strings are not identical
Also possible would be:
#echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%F in ('dir /A-D /B /S "%USERPROFILE%\test\*.aaxplugin" 2^>nul') do (
set "FilePath=%%~dpF"
if not "!FilePath:\x64\=!" == "!FilePath!" "%ProgramFiles%\Sugar Bytes\TransVST\TransVST_Fixer.exe" "%%F"
)
endlocal
But command DIR is not really necessary as it can be seen on first provided code.
But if the application TransVST_Fixer.exe for some unknown reason does its job right only with directory of file being also the current directory, the following batch code could be used instead of first code using the commands pushd and popd:
#echo off
setlocal EnableDelayedExpansion
for /R "%USERPROFILE%\test" %%F in (*.aaxplugin) do (
set "FilePath=%%~dpF"
echo !FilePath!
if /I "!FilePath:~-5!" == "\x64\" (
pushd "%%~dpF"
"%ProgramFiles%\Sugar Bytes\TransVST\TransVST_Fixer.exe" "%%~nxF"
popd
)
)
endlocal
There is one more difference in comparison to first code. Now the last 5 characters of path of file are compared case-insensitive with the string \x64\. Therefore the file must be really inside a folder with name x64 or X64. A folder with name x64 or X64 anywhere else in path of file does not result anymore in a true state for the condition as in first two batch codes.
But if for some unknown reason it is really necessary to run the application in same folder as the found *.aaxplugin and the directory of the file must be the current directory, the following batch code could be used:
#echo off
setlocal EnableDelayedExpansion
for /R "%USERPROFILE%\test" %%# in (*.aaxplugin) do (
set "FilePath=%%~dp#"
if /I "!FilePath:~-5!" == "\x64\" (
pushd "%%~dp#"
"%%~dp#TransVST_Fixer.exe" "%%~nx#"
popd
)
)
endlocal
The path of the file referenced with %%~dpF always ends with a backslash which is the reason why there is no backslash left of TransVST_Fixer.exe (although command processor could handle also file with with two backslashes in path).
In batch code above character # is used as loop variable because %%~dp#TransVST_Fixer.exe is easier to read in comparison to %%~dpFTransVST_Fixer.exe. It is more clear for a human with using # as loop variable where the reference to loop variable ends and where name of application begins. For the command processor it would not make a difference if loop variable is # or upper case F.
A lower case f would work here also as loop variable, but is in general problematic as explained on Modify variable within loop of batch script.
For understanding the used commands and how they work, open a command prompt window, execute there the following commands, and read entirely all help pages displayed for each command very carefully.
dir /?
echo /?
endlocal /?
for /?
if /?
popd /?
pushd /?
set /?
setlocal /?
Your question isn't quite clear, but it seems, something like this should work:
for /f "delims=" %%f in ('dir /b /s X64\*.ext') do "%%~dpfMyExe.exe" "%%f"
Maybe you have to change directory to each folder (depends on your .exe):
for /f "delims=" %%d in ('dir /B /ad') do (
pushd "%%d"
for /f "delims=" %%f in ('dir /b "contents\x64\*.ext"') do (
cd Contents\x64
MyExe.exe "%%f"
)
popd
)
Assuming:
The Directory structure is fixed and the files are indeed in a subfolder contents\X64\.
MyExe.exe is the same (name) in every folder.
There is only one file *.ext in every folder.
I'll give you the script I created for doing so, hope it works for you
for /d %%d IN (./*) do (cd "%%d/Contents/x64" & "../../../TransVST_Fixer.exe" "%%d" & cd "/Program Files (x86)\Common Files\Avid\Audio\Plug-Ins")
Please note that I placed the fixer inside the root folder so I just have to copy it once. You have to place it inside your root folder and execute it. What it does:
iterate over each folder
for each one it enters /Contents/x64, executes the fixer (wich is 3 levels above) and after that returns to the original folder.
If you have your plugins in a different folder, you just have to change this part replacing the path for the one you have your plugins in.
cd "/Program Files (x86)\Common Files\Avid\Audio\Plug-Ins"
REMEMBER to place the script on that folder. For this example I place my script on the folder "/Program Files (x86)\Common Files\Avid\Audio\Plug-Ins" and run it (as a .bat).
PS: the fixer will place the fixed plugins in "C:\Users\Public\modified" (just read the screen while executing, it gives you the new files path. If you want to move them to the right path, you can execute this from the new files path ("C:\Users\Public\modified")
for %%d IN (*.aaxplugin) do (mkdir "%%d_temp/Contents\x64" & move "%%d" "%%d_temp/Contents\x64/%%d" & rename "%%d_temp" "%%d")
with that, I iterate over every plugin and create a folder with the same name (I create _temp because of name colision, after moving the file I rename it to the correct one), also with the subfolder "/Contents/x64", and move the plugin inside. Once donde, you can just take the resulting folders and place them in their correct path.
Hope it works, for me it works like a charm.

Drag and drop to batch file from UNC - how to capture %cd%

I have a batch file:
#ECHO OFF
Set dd=%DATE:~0,2%
Set mm=%DATE:~3,2%
Set yyyy=%DATE:~6,4%
Set hh=%TIME:~0,2%
Set ii=%TIME:~3,2%
Set ss=%TIME:~6,2%
Set zipFileHandle=%yyyy%-%mm%-%dd%-%hh%-%ii%-%ss%
Set files=%*
%~dp0\7za a -t7z %cd%\%zipFileHandle%.7z %files%
When I drop a group of files and/or directories on it, it compresses them into a dated .7z file in the root folder they all came from.
The problem is that if I drop network files, with a path starting with \\, the batch file changes the value of the save directory to C:\Windows.
How can I get the value of %cd% before cmd changes it to the system root?
If that's not possible, is it possible to get the common root folder from the variable %files%?
You should get next message:
'\\computer\path'
CMD.EXE was started with the above path as the current directory.
UNC paths are not supported. Defaulting to Windows directory.
So you could use next:
%~dp07za a -t7z %~dp1%zipFileHandle%.7z %files%
Note that \ backslash could be omitted using %~dp0 and %~dp1 as the ~dp modifier expands a %variable to a Path only including a trailing \ backslash.
And if source folder name contains spaces, use quoted target file name rather:
%~dp07za a -t7z "%~dp1%zipFileHandle%.7z" %files%
You could pushd %~dp1 before calling 7za. That temporarily maps the UNC path of the 1st dragged-and-dropped file as a network drive letter and changes directory to it. The mapping disappears as soon as the script exists.
Additionally, 7za has exit codes you might make use of for fault tolerance.
#echo off
setlocal
for /f "tokens=2 delims=.=" %%I in (
'wmic os get localdatetime /format:list ^| find "="'
) do set "t=%%I"
set "handle=%t:~0,4%-%t:~4,2%-%t:~6,2%_%t:~8,2%-%t:~10,2%-%t:~12,2%"
pushd "%~dp1"
"%~dp0\7za" a -t7z "%handle%.7z" %* || (
if ERRORLEVEL 2 (
echo Zipping failed.
pause
) else (
echo Zipping completed with errors, possibly because a file is locked by another process.
pause
)
)

How to append a list of directories provided in a text file to PATH variable?

I have a text file list.txt consisting of directories as follows.
C:\Program Files\gs\gs9.07\bin
C:\Program Files (x86)\Adobe\Reader 11.0\Reader
C:\Program Files (x86)\Google\Chrome\Application
C:\Program Files (x86)\cwRsync\bin
C:\Program Files (x86)\PDF Labs\PDFtk Server\bin
I want to create a batch file that appends each item in list.txt to system PATH environment variable permanently.
My failed attempt is as follows.
rem batch.bat
for /f "delims=" %%x in (list.txt) do (setx PATH "%PATH%;%%x" /m)
I invoke batch.bat with administrative privilege but nothing appended to PATH. Could you help me solve it?
#ECHO OFF
setlocal
SET testvar=%PATH%
FOR /f "delims=" %%x IN (list.txt) DO (
CALL SET testvar=%%testvar%%%%x;
)
setx testvar "%testvar%"
Well - this sets 'testvar' for future invocations - I don't want to change my PATH; existing instances, including the current, will be unchanged (as documented.)
The problem with your implementation is that when a FOR loop is parsed, any %var% is replaced by its then-existing value before the loop is executed. In consequence, your command was executed as
setx path "(yourexistingpath);C:\Program Files\gs\gs9.07\bin"
setx path "(yourexistingpath);C:\Program Files (x86)\Adobe\Reader 11.0\Reader"
...
which should have set your path according with the final line from your file (only) appended.
...and of course all you need to do to set TESTVAR in the CURRENT environment is to remove the SETLOCAL (which is actually only there to keep my environment clean while testing) OR to add a line
ENDLOCAL&set testvar=%testvar%

Resources