I'm trying to write a small script to find the absolute path of Rscript in a machine running Windows OS. I assume that Rscript must be found under C:\Program Files\R\R-x.x.x directory, where x.x.x represents any version of R. I have written the following script based on several threads (Find file and return full path using a batch file).
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /d %%a in ("C:\Program Files\R\") do (
if "%%~nxa"=="Rscript.exe" (
set p=%%~dpnxa
)
)
Unfortunately, the if condition assigns p to every file and folder in C:\Program Files\R\R-x.x.x. If anyone has any idea of how to find and assign p properly, I would really appreciate it!
Regards,
Juan
EDIT
I'm adding my full script
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
for /R %%a in ("C:\Program Files\R\R-*") do (
if /i "%%~nxa"=="Rscript.exe" (
set "p=%%~fa"
)
)
if defined p (
echo %p%
) else (
echo File not found
)
%p% runShinyApp.R 1> ShinyApp.log 2>&1