按主机名,日期和时间的文件路径

时间:2014-08-06 13:17:32

标签: date batch-file time hostname xcopy

您好我是批处理文件编码的新手。在过去的几个月里,我一直在教自己Excel VBA,StackOverflow对我来说是一个非常有用的网站。这是我想要实现的目标。

我的公司在IP视频监控服务器上工作很多。在我们处理服务器之前,我们喜欢为我们使用的各种程序拍摄日志和配置文件的快照,以防出现问题。我想把它归结为一个BAT文件,它位于技术人员的USB记忆棒上,带有一个自动运行文件,当USB插入机器时,该文件将执行BAT文件。该程序将发送到各种文件并将它们复制到文件路径:\ hostname \ date \ time \ originalfoldername \ thisfile.xml我一直在从各个站点提取代码,这里是我来的到目前为止,让我到文件路径:\ date \ time \ originalfoldername \ thisfile.xml

@echo off 
rem COPYIT.BAT transfers all files in all subdirectories of
rem the source drive or directory (%1) to the destination rem drive or directory (%2) 


for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%\%ldt:~8,2%%ldt:~10,2%

echo %ldt%



xcopy "C:\ProgramData\Milestone\XProtect Recording Server"          "\"%ldt%"\XProtect Recording Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Management Server"         "\"%ldt%"\XProtect Management Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Management Client"         "\"%ldt%"\XProtect Management Client\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Event Server"              "\"%ldt%"\XProtect Event Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Log Server"                "\"%ldt%"\XProtect Log Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Data Collector Server"     "\"%ldt%"\XProtect Data Collector Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Report Web Server"         "\"%ldt%"\XProtect Report Web Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Service Channel Server"    "\"%ldt%"\XProtect Service Channel Server\" /s /e
xcopy "C:\ProgramData\Milestone\XProtect Smart Client"              "\"%ldt%"\XProtect Smart Client\" /s /e


if errorlevel 4 goto lowmemory 
if errorlevel 2 goto abort 
if errorlevel 0 goto exit 

:lowmemory 
echo Insufficient memory to copy files or 
echo invalid drive or command-line syntax. 
goto exit 

:abort 
echo You pressed CTRL+C to end the copy operation. 
goto exit 

:exit 

我还找到了主机名的代码,但我无法弄清楚如何将它们组合在一起。这是代码:

FOR /F "usebackq" %%i IN (`hostname`) DO SET MYVAR=%%i
ECHO %MYVAR%

有人可以帮忙吗?感谢。

0 个答案:

没有答案