每天批处理文件到不同的位置

时间:2015-06-20 04:58:59

标签: batch-file

尝试编写批处理文件(Windows环境) 这将采取相同的txt文件,并将其复制到每天的位置,我可以管理,但我正在努力的是,我是如何让它每天复制到不同的位置,即: - mon / tue / wed / thur / fri / sat / sun这可能吗?

1 个答案:

答案 0 :(得分:0)

下一段代码片段可以提供帮助:

@ECHO OFF
SETLOCAL enableextensions

set "filename=the same txt file.txt"
set "daynames=SunMonTueWedThuFriSat"

rem the current matching day of the current week (0-6, Sunday being 0): multiplied by 3
for /F %%g in ('
  wmic path Win32_localtime get DayOfWeek /value^|findstr "="
  ') do for /F %%G in ("%%g") do set /A "%%G*3"

rem the day name (three-chars abbreviation)
SETLOCAL enabledelayedexpansion
  set "DayOfWeekStr=!daynames:~%DayOfWeek%,3!"
ENDLOCAL&set "DayOfWeekStr=%DayOfWeekStr%"

rem the day name (three-chars abbreviation) - another approach
call set "DayOfWeekTrs=%%daynames:~%DayOfWeek%,3%%"

rem next two commands merely ECHOed for debugging purposes
ECHO mkdir %DayOfWeekStr% 2>NUL
ECHO copy /B "%filename%" "%DayOfWeekStr%\%filename%" 

rem next two lines for debugging purposes only
echo(
set DayOfWeek

<强>输出

==>SO\30950430.bat
mkdir Sat
copy /B "the same txt file.txt" "Sat\the same txt file.txt"

DayOfWeek=18
DayOfWeekStr=Sat
DayOfWeekTrs=Sat

==>