我正在尝试创建一个批处理文件,该文件创建一个以明天的日期命名的新文件夹,但我还需要它从今天的日期文件夹中获取文件。我的代码是写的,所以当我把%mm %% dd %% yy%放入时,它只能通过明天的日期来设置它。我需要帮助编辑它,以便以某种方式抓住它们。这是我的代码
@echo off
setlocal enableextensions disabledelayedexpansion
rem Retrieve data
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
rem Remove padding from date elements and increase day
set /a "y=%YYYY%", "m=100%MM% %% 100", "d=(100%DD% %% 100)+1"
rem Calculate month length
set /a "ml=30+((m+m/8) %% 2)" & if %m% equ 2 set /a "ml=ml-2+(3-y %% 4)/3-(99-y %% 100)/99+(399-y %% 400)/399"
rem Adjust day / month / year for tomorrow date
if %d% gtr %ml% set /a "d=1", "m=(m %% 12)+1", "y+=(%m%/12)"
rem Pad date elements and translate again to original variables
set /a "m+=100", "d+=100"
set "YYYY=%y%"
set "YY=%y:~-2%"
set "MM=%m:~-2%"
set "DD=%d:~-2%"
echo Tomorrow: %YYYY% / %MM% / %DD%
mkdir "C:\Users\name\Desktop\DNFB %mm%%dd%%yy%\"
mkdir "C:\Users\name\Desktop\DNFB %mm%%dd%%yy%\DNFB"
xcopy /s "C:\Users\name\Desktop\"DNFB %mm%%dd%%yy%"\file*.xls" "C:\Users\name\Desktop\DNFB %mm%%dd%%yy%\"
xcopy / s" C:\ Users \ name \ Desktop \" DNFB%mm %% dd %% yy%"(TODAY)\ file * .xls" " C:\ Users \ name \ Desktop \ DNFB%mm %% dd %% yy%(TOMORROW)\" - 从标有" DNFB 010815"的文件夹中获取文件。并将其粘贴到文件夹" DNFB 010915"(明天)
甚至可能吗?还是太矛盾了。感谢
答案 0 :(得分:1)
你有逻辑。使用更多变量
@echo off
setlocal enableextensions disabledelayedexpansion
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "td.YY=%dt:~2,2%"
set "td.YYYY=%dt:~0,4%"
set "td.MM=%dt:~4,2%"
set "td.DD=%dt:~6,2%"
rem Remove padding from date elements and increase day
set /a "y=%td.YYYY%", "m=100%td.MM% %% 100", "d=(100%td.DD% %% 100)+1"
rem Calculate month length
set /a "ml=30+((m+m/8) %% 2)" & if %m% equ 2 set /a "ml=ml-2+(3-y %% 4)/3-(99-y %% 100)/99+(399-y %% 400)/399"
rem Adjust day / month / year for tomorrow date
if %d% gtr %ml% set /a "d=1", "m=(m %% 12)+1", "y+=(%m%/12)"
rem Pad date elements and set tomorrow variables
set /a "m+=100", "d+=100"
set "tm.YYYY=%y%"
set "tm.YY=%y:~-2%"
set "tm.MM=%m:~-2%"
set "tm.DD=%d:~-2%"
echo Today : %td.YYYY% / %td.MM% / %td.DD%
echo Tomorrow: %tm.YYYY% / %tm.MM% / %tm.DD%