我目前正在尝试提供一个脚本,将多个文件从一个位置复制到程序的操作位置,然后启动该应用程序。目前我有这个:
xcopy /s /v /z "I:\test\20150520\Files\stmt" "C:\Users\test\Desktop\test2"
PAUSE
START C:\Windows\NOTEPAD.EXE
这个脚本似乎没有问题,但我遇到的问题是我的目录每天都在更改 20150520 。下面的目录始终是相同的,只是每天更改的目录,我也需要脚本来执行此操作。
无论如何,这可以做到吗?
答案 0 :(得分:0)
| synchronous | asynchronous
-------------------+--------------------------+-------------------------+
interactive | shell-command | async-shell-command
programmatically | call-process | start-process
interactive: from the editing environment
programmatically: from elisp
synchronous: start and wait till done
asynchronous: start and return immediately while it is running in the background.
答案 1 :(得分:0)
下一个脚本需要一个有效参数(请参阅下面提供的代码和示例中的%~1
);如果参数未找到或与有效文件夹不匹配,则获取今天的日期(参见:getToday
子例程)。
@ECHO OFF >NUL
SETLOCAL enableextensions
set "dayFolder=%~1"
if "%dayFolder%"=="" call :getToday
if not exist "I:\test\%dayFolder%\Files\stmt\" call :getToday
if exist "I:\test\%dayFolder%\Files\stmt\" (
xcopy /s /v /z "I:\test\%dayFolder%\Files\stmt" "C:\Users\test\Desktop\test2"
) else (
echo invalid "%~1" parameter or "%dayFolder%" folder does not exist
)
PAUSE
START C:\Windows\NOTEPAD.EXE
goto :eof
:getToday
for /F "tokens=2 delims==" %%G in (
'wmic OS get LocalDateTime /value'
) do @for /F "tokens=*" %%x in ("%%G") do (
set "dayFolder=%%~x"
)
set "dayFolder=%dayFolder:~0,8%"
goto :eof
此处for
子例程中的:getToday
循环为
%%G
检索LocalDateTime
值; %%x
删除返回值中的结尾回车(wmic
行为:每个输出行以0x0D0D0A
结尾,而不是公共0x0D0A
})。<强>输出强>:
==>D:\bat\StackOverflow\30356205.bat
invalid "" parameter or "20150521" folder does not exist
Press any key to continue . . .
==>D:\bat\StackOverflow\30356205.bat 2015 05 19
invalid "2015" parameter or "20150521" folder does not exist
Press any key to continue . . .