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.
- @echo off
- set SourcePath="C:\BMS Valcea\RESOURCES\BMS"
- :: %userprofile% will get the current user path, you can change to any other folder
- set DestinationPath="%userprofile%\Documents\Rapoarte"
- :: root names of files to be moved
- set RootWater=RaportContorizareApa
- set RootHeat=RaportContorizareCaldura
- set RootElectric=RaportContorizareElectrice
- set RootGas=RaportContorizareGaz
- :: set the minimum file age (in days)
- set DaysOld=1
- :: move the files older than 1 day
- robocopy %SourcePath% %DestinationPath% "%RootWater%"*".csv" /mov /minage:%DaysOld%
- robocopy %SourcePath% %DestinationPath% "%RootHeat%"*".csv" /mov /minage:%DaysOld%
- robocopy %SourcePath% %DestinationPath% "%RootElectric%"*".csv" /mov /minage:%DaysOld%
- 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.
- @echo off
- set SourcePath="C:\BMS Valcea\RESOURCES\BMS"
- :: %userprofile% will get the current user path, you can change to any other folder
- set DestinationPath="%userprofile%\Documents\Rapoarte"
- :: root names of files to be moved
- set RootWater=RaportContorizareApa
- set RootHeat=RaportContorizareCaldura
- set RootElectric=RaportContorizareElectrice
- set RootGas=RaportContorizareGaz
- :: move all the files
- robocopy %SourcePath% %DestinationPath% "%RootWater%"*".csv" /mov
- robocopy %SourcePath% %DestinationPath% "%RootHeat%"*".csv" /mov
- robocopy %SourcePath% %DestinationPath% "%RootElectric%"*".csv" /mov
- 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.