batch-file - 如何使用变量创建批处理脚本。这会生成文件,但不会移动文件并删除源文件
问题描述
@echo off
set date="%date:~4,2%-%date:~7,2%-%date:~10,4%"
if not exist "%USERPROFILE%\Documents\python_scripts\TEST\logs\grab_ip\%date%" mkdir "%USERPROFILE%\Documents\python_scripts\TEST\logs\grab_ip\%date%"
set source="%USERPROFILE%\Documents\python_scripts\TEST\logs\grab_ip"
set target="%USERPROFILE%\Documents\python_scripts\TEST\logs\grab_ip\%date%"
Echo Source is %source%
Echo Target is %target%
Pause
Robocopy.exe %source% %target%
Pause
解决方案
Here's a 3
line batch-file, which may, (if my assumptions are correct), do what you want:
@Set "source=%USERPROFILE%\Documents\python_scripts\TEST\logs\grab_ip"
@Set "_date=%DATE:~-10%"
@"%__APPDIR__%Robocopy.exe" "%source%" "%source%\%_date:/=-%" /E /Move /XD "%_date:/=-%">NUL
The above is an entire script, do not add or remove any other line or command, before testing. The script assumes your %DATE%
value separators are forward slashes, if they are not please modify as necessary.
推荐阅读
- android - AsyncTask Android 中的致命信号 6 (SIGABRT)
- python - Python 等价于 Java Exception with cause
- php - 使用 AJAX 在 HTML 页面中获取 XML 数据
- powerbi - Power BI 在同一行显示标题和值
- python - 试图理解使用 inplace = true vs false 更改列名
- c++ - 使用c ++连续将数据从服务器发送到接收器
- python - 使用 matplotlib/seaborn 从 pivot_table 绘制 sub_plots
- spring - 在 Spring 执行器中:HealthEndPoint.health() 是否给出与调用 /health 端点相同的结果?
- java - 解析时获取 com.fasterxml.jackson.core.JsonParseException
- jenkins - 在 Jenkins 的 JMeter 负载测试期间获取服务器的 CPU 和内存使用情况图