I want to create a .bat file to do the following things in the following order:
1) Get the directory path of a service
2) copy all files from that directory (files only) to a subfolder named "save"
The Service name exists and if I run "wmic service where "name='SERVICENAME'" get PathName"
I get the Path, but for some reason the .bat files does not work as expected.
So far I have:
@echo off
setlocal
:PROMPT
SET /P UPDATESERVICE=Update Service (Y/[N])?
IF /I "%UPDATESERVICE%" NEQ "Y" GOTO END
FOR /F "tokens=*" %%g IN ('wmic service where "name='SERVICENAME'" get PathName') do (SET SERVICEPATH=%%g)
FOR %%a IN ("%SERVICEPATH%") DO FOR %%b IN ("%%~dpa.") SERVICEPATH=%%~dpb&%%~nxb
if not exist "%SERVICEPATH%\Save\" mkdir %SERVICEPATH%\Save
echo f | xcopy %SERVICEPATH%* %SERVICEPATH%\Save* /L /R
:END
endlocal
This script should get the directory path of the service and copy all file from it and put them to a subfolder called "save". The idea is to make a backup of the existing files in the subdirectory and copy the new files over.