0

Trying to write a batch file ( windows environment ) that will take the same txt file and copy it to a location on a daily basis, that i can manage, but what i'm struggling with, is how i get it to copy into a different location each day ie:- mon/tue/wed/thur/fri/sat/sun is this possible ?

1 Answers1

0

Next code snippet could help:

@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

Output:

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

DayOfWeek=18
DayOfWeekStr=Sat
DayOfWeekTrs=Sat

==>
JosefZ
  • 28,460
  • 5
  • 44
  • 83