Copy files without Task Scheduler

Microsoft Windows
Post Reply
User avatar
MigrationUser
Posts: 336
Joined: 2021-Jul-12, 1:37 pm
Contact:

Copy files without Task Scheduler

Post by MigrationUser »

24 Feb 2009 16:13
Acris

Hello

is it possible to copy files one day in the week without using Robocopy and the AT command?


I want to save my file on an external hard drive every Friday at 12:00, but without using the task scheduler and copy only new files?
I know it would be easier with Robocopy and At but I have no right to use
can you help me ?

thanks a lot.

Acris

----------------------------

#2 24 Feb 2009 17:31
bluesxman


Without using "robocopy", copying only updated files would be achievable using "xcopy /m /s". Though prior to the first run, you'd want to use "attrib /s -a" to clear the archive attribute, to make sure that the baseline includes all files.

Without using AT/Task Scheduler? You'll be struggling.

Assuming that you can't install some 3rd party scheduling program, your only recourse would be to have a script that starts at every logon (or perhaps just on Fridays) then stays running all the time, waiting until Friday noon to do its thing. This should be achievable, but it's not exactly ideal -- you'd also have to be careful to not close it by mistake.

Perhaps you could set up an xcopy script as suggested, then just remember to kick it off at 12:00 on Friday...? 8-)

cmd | *sh | ruby | chef

----------------------------

#3 24 Feb 2009 19:25
avery_larry


I believe some version of xcopy /e /d: will get you new files only.

You can setup a script that basically checks the %time% and %date% variables to see if the time has passed 12:00 noon on Friday.

Ted

----------------------------

#4 25 Feb 2009 08:13
Acris


ok thanks a lot.
i use xcopy

the ideal solution would be to make a logon script to run every Friday but I do not see how with %time% and %date% variables.

----------------------------

#5 25 Feb 2009 09:50
bluesxman


I tend to do something like this to get the day of the week:

Code: Select all

echo:WScript.Quit^(DatePart^("w",date^)^) >"temp.vbs"
cscript //nologo temp.vbs
set dayofweek=%errorlevel%
del temp.vbs
This results in %dayofweek% being an integer from 1 to 7, where 1 = Sunday and 7 = Saturday.

Hope that helps.

Last edited by bluesxman (25 Feb 2009 09:51)

cmd | *sh | ruby | chef

----------------------------

#6 25 Feb 2009 20:00
Simon Sheppard


Heres how to get the day of the week in pure batch

Code: Select all

set dd=25
set mm=2
set yy=2008

:: Modified Julian Day 0 on 17 Nov, 1858 is a Wednesday
set Days=WedThuFriSatSunMonTue
set /a z=14-mm,z/=12 
set /a jy=yy-z
set /a jm=12*z+mm-3
set /a mjd=153*jm+2,mjd/=5
set /a mjd=mjd+dd+365*jy+jy/4-jy/100+jy/400-678882
set /a "DoW=mjd%%7"
set /a DoW*=3
call set DoW=%%Days:~%DoW%,3%%
echo %DoW%
----------------------------

#7 25 Feb 2009 21:28
avery_larry
Acris wrote:

ok thanks a lot.
i use xcopy

the ideal solution would be to make a logon script to run every Friday but I do not see how with %time% and %date% variables.
Oops. On Win2000, the %date% variable includes the day of the week. On XP it does not.

Last edited by avery_larry (25 Feb 2009 21:56)

----------------------------

#8 25 Feb 2009 21:56
avery_larry


Modifying Simon's code:

Code: Select all

for /f "tokens=1-3 delims=/" %%a in ("%date%") do (
   set dd=%%b
   set mm=%%a
   set yy=20%%c
)

if 1%dd:~0,1%==10 set dd=%dd:~1,1%
if 1%mm:~0,1%==10 set mm=%mm:~1,1%

set Days=WedThuFriSatSunMonTue
set /a z=14-mm,z/=12 
set /a jy=yy-z
set /a jm=12*z+mm-3
set /a mjd=153*jm+2,mjd/=5
set /a mjd=mjd+dd+365*jy+jy/4-jy/100+jy/400-678882
set /a "DoW=mjd%%7"
set /a DoW*=3
call set DoW=%%Days:~%DoW%,3%%
echo %DoW%
This does not take into account the possibility of different date display (mm/dd/yy or dd/mm/yy or mm/dd/yyyy or etc. . . .) There's a script running around on this site which will also account for the different date display formats. Once you get the day of the week defined, you can do this -- partially tested:

Code: Select all

@echo off

:evaluate
call :set_current_day
if not %DoW%==Fri (
   echo It's not even Friday.
   echo Here you can just exit the script with
   echo goto :eof
   echo or you can wait and retest
   ping -w 800 -n 39601 127.0.0.1 >nul 2>&1
   goto evaluate
)

echo If we get here, it's Friday

call :set_current_hour
if %hr% GTR 11 (
   echo The current time is already past 12:00 so we don't want to run the script today.
   echo You can exit the script with goto :eof or you can
   echo wait and retest
   ping -w 800 -n 39601 127.0.0.1 >nul 2>&1
   goto evaluate
)

:wait_for_noon

echo If we're here, it's Friday and it's before noon so we need to watch for the changeover
echo to noon and then run.

call :set_current_hour
if %hr%==12 goto what_to_actually_do

echo it's not noon yet, wait 20 seconds and check again
ping -w 800 -n 21 127.0.0.1 >nul 2>&1
goto wait_for_noon
goto :eof


:what_to_actually_do
echo We're here!  It's noon on Friday.
echo stick your commands here.


echo When finished with the commands, you can exit with goto :eof
echo or you can start all over again and wait for next week.
ping -w 800 -n 39601 127.0.0.1 >nul 2>&1
goto evaluate


:set_current_day
for /f "tokens=1-3 delims=/" %%a in ("%date%") do (
   set dd=%%b
   set mm=%%a
   set yy=20%%c
)

if 1%dd:~0,1%==10 set dd=%dd:~1,1%
if 1%mm:~0,1%==10 set mm=%mm:~1,1%

set Days=WedThuFriSatSunMonTue
set /a z=14-mm,z/=12 
set /a jy=yy-z
set /a jm=12*z+mm-3
set /a mjd=153*jm+2,mjd/=5
set /a mjd=mjd+dd+365*jy+jy/4-jy/100+jy/400-678882
set /a "DoW=mjd%%7"
set /a DoW*=3
call set DoW=%%Days:~%DoW%,3%%
goto :eof

:set_current_hour
for /f "tokens=1 delims=:" %%a in ("%time%") do set hr=%%a
goto :eof
----------------------------

#9 09 Mar 2009 10:18
Acris


Thanks a lot It works :D .
Post Reply