[英].bat file to get Service Directory Path folder and copy the files from that folder to subfolder of the same directory
I want to create a .bat file to do the following things in the following order: 我想创建一个.bat文件以按以下顺序执行以下操作:
1) Get the directory path of a service 1)获取服务的目录路径
2) copy all files from that directory (files only) to a subfolder named "save" 2)将该目录中的所有文件(仅文件)复制到名为“保存”的子文件夹中
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. 服务名称存在,并且如果我运行"wmic service where "name='SERVICENAME'" get PathName"
路径"wmic service where "name='SERVICENAME'" get PathName"
,则会获取路径,但是由于某种原因,.bat文件无法按预期工作。
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. 想法是对子目录中的现有文件进行备份,然后复制新文件。
I got it working with this 我明白了
@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='MyServiceName'" get PathName') do (SET SERVICEPATH=%%g)
FOR %%a IN ("%SERVICEPATH%") DO FOR %%b IN ("%%~dpa.") do SERVICEPATH=%%~dpb&%%~nxb
if not exist "%SERVICEPATH%\Save\" mkdir %SERVICEPATH%\Save
echo f | xcopy /f /y %SERVICEPATH%* %SERVICEPATH%\Save*
:END
endlocal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.