If the user can specify the path as a parameter to the batch file, that is the best option since "%~1" is less problematic than "%filename%" like I said in a comment to Helen's answer. It would look something like:
setlocal ENABLEEXTENSIONS
FOR %%A IN ("%~1") DO (
IF /I "%%~xA"==".rar" goto ziprar
IF /I "%%~xA"==".zip" goto ziprar
)
goto folder
If you can't use a parameter, the best I could come up with is:
setlocal ENABLEEXTENSIONS
REM set file="f~p 'o%OS%!OS!^o%%o.rar"
set /p file=Enter a folder path or a zip/rar file name:
FOR /F "tokens=*" %%A IN ("%file%") DO (
IF /I "%%~xA"==".rar" goto ziprar
IF /I "%%~xA"==".zip" goto ziprar
)
goto folder
There is a possibility that there is a valid filename that causes syntax errors, but I did not find one during my limited testing.
You might also want to consider a basic folder check rather than checking file extensions:
IF EXIST "%~1\*" (goto folder) ELSE goto ziprar