首页 > 解决方案 > 如何使用变量创建批处理脚本。这会生成文件,但不会移动文件并删除源文件

问题描述

发行人图片

@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

标签: batch-file

解决方案


Here's a 3 line , 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.


推荐阅读