Your set
is setting %OWNPATH %
(note the space between OWNPATH
and the =
). Therefore %OWNPATH%
(with no space) is not defined, and for /r %OWNPATH% %%F ...
gets expanded to for /r %%F
, and the for
loop ends up looking in the current directory (which is C:\Windows\System32 when run as administrator).
Get in the habit of doing your assignments like this to avoid that common mistake:
set "OWNPATH=%~dp0"