Task Scheduler to move files

Tested on Windows 10, 64bit

If you want to move the logs created by BMS to another folder at regular intervals of time, you can use Task Scheduler and a simple batch file.

Jump to

Batch file

Here is how the batch file looks like – you can copy-paste it in Notepad and save the file with .bat extension, let’s say BkpFilesSchedule.bat

It was considered that only older files should be moved. The minimum file age is considered one day in the example below.

 
 
  1. @echo off
  2. set SourcePath="C:\BMS Valcea\RESOURCES\BMS"
  3. :: %userprofile% will get the current user path, you can change to any other folder
  4. set DestinationPath="%userprofile%\Documents\Rapoarte"
  5. :: root names of files to be moved
  6. set RootWater=RaportContorizareApa
  7. set RootHeat=RaportContorizareCaldura
  8. set RootElectric=RaportContorizareElectrice
  9. set RootGas=RaportContorizareGaz
  10. :: set the minimum file age (in days)
  11. set DaysOld=1
  12. :: move the files older than 1 day
  13. robocopy %SourcePath% %DestinationPath% "%RootWater%"*".csv" /mov /minage:%DaysOld%
  14. robocopy %SourcePath% %DestinationPath% "%RootHeat%"*".csv" /mov /minage:%DaysOld%
  15. robocopy %SourcePath% %DestinationPath% "%RootElectric%"*".csv" /mov /minage:%DaysOld%
  16. robocopy %SourcePath% %DestinationPath% "%RootGas%"*".csv" /mov /minage:%DaysOld%

Task Scheduler

Now, open Task Scheduler and choose from the menu Action =>Create Task.

General

Add a name for the task and check Run whether user is logged or not.

Triggers

Click on New and define when the task should run – daily, monthly etc, if it will repeat during a day etc.

Action

Click on New. Here you have to specify the batch file to be executed, the one you created above.

Conditions & Settings

Here you make additional settings as you need.

Click OK to save the task. You’ll be prompted to enter the windows password.

Manually execute to copy all files

The batch file would be simpler, without specifying the age of file. Save the file on a preferred place (eg. Desktop) as BkpFilesNow.bat. You can run it any time you need.

 
 
  1. @echo off
  2. set SourcePath="C:\BMS Valcea\RESOURCES\BMS"
  3. :: %userprofile% will get the current user path, you can change to any other folder
  4. set DestinationPath="%userprofile%\Documents\Rapoarte"
  5. :: root names of files to be moved
  6. set RootWater=RaportContorizareApa
  7. set RootHeat=RaportContorizareCaldura
  8. set RootElectric=RaportContorizareElectrice
  9. set RootGas=RaportContorizareGaz
  10. :: move all the files
  11. robocopy %SourcePath% %DestinationPath% "%RootWater%"*".csv" /mov
  12. robocopy %SourcePath% %DestinationPath% "%RootHeat%"*".csv" /mov
  13. robocopy %SourcePath% %DestinationPath% "%RootElectric%"*".csv" /mov
  14. robocopy %SourcePath% %DestinationPath% "%RootGas%"*".csv" /mov

 

Note: if you want to copy the files instead of moving them, remove the /mov from the robocopy commands.