简体   繁体   English

.bat文件以获取“服务目录路径”文件夹,并将文件从该文件夹复制到同一目录的子文件夹

[英].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.

相关问题 获取与bat文件位于同一目录中的文件夹名称 - Get name of folder in same directory as bat file 批处理文件以在目录中搜索文件列表并复制到单个文件夹 - Batch file to search directory for list of files and copy to single folder 使用目录上的通配符从文件夹复制内容 - Copy Contents From Folder Using Wildcard On The Directory 如何使用此批处理文件将所有* .txt文件从子文件夹复制到批处理文件文件夹? - How to copy all *.txt files from subfolder to batch file folder using this batch-file? 创建bat文件以将文件夹从一个目录复制到另一个目录:事先回答cmd问题 - Creating bat file for copying folder from one directory to the other: answering cmd questions beforehand 如何获取 cmd 中文件夹和子文件夹中存在的文件列表(完整路径) - How to get list (full path) of files exist in folder and subfolder in cmd Nsis Delete文件夹和子文件夹-安装程序目录中 - Nsis delete folder & subfolder — inside installer directory 批处理文件以在文件夹中创建新的子文件夹,将文件移动到目录中所有文件夹的新创建的子文件夹 - batch file to create new subfolder in folder, move file to newly created subfolder, for all folders in directory 如何将基于列表(txt)的文件批量复制到具有相同目录结构的另一个文件夹中? - How to batch copy files based on a list (txt) in to another folder with same directory structure? 共享文件夹中没有这样的文件或目录 - no such file or directory at share folder
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM