Due to the issues with %DATE%
, as noted in the comments to the answer from Cyberclops, here's single line command, which can be run from a batch file or Command Prompt, cmd.exe
:
@PowerShell -NoP "XCopy \"C:\Users\DikS\Documents\" \"D:\Backups\DikS\Docs\$(Get-Date -F yyyy-MM-dd)\\\" /S/Y">Nul
In the Command Prompt, you can optionally remove the leading @
.
You can obviously run it from a Powershell Prompt or script too:
XCopy "C:\Users\DikS\Documents" "D:\Backups\DikS\Docs\$(Get-Date -F yyyy-MM-dd)\" /S/Y >$Null
Please remember to adjust the source, C:\Users\DikS\Documents
, and destination, D:\Backups\DikS\Docs
as necessary.
How to use the Task Scheduler is out of the scope of this site, which is about programming as opposed to the use of OS GUI tools.
Edit
If you are struggling with understanding what to replace, here's a batch script version of the upper code to make it easier for you:
@Echo Off
Set "SrcDir=C:\Users\DikS\Documents"
Set "DstDir=D:\Backups\DikS\Docs"
PowerShell -NoP "XCopy \"%SrcDir%\" \"%DstDir%\$(Get-Date -F yyyy-MM-dd)\\\" /S/Y">Nul
…and the lower code as a powershell script:
$SrcDir = "C:\Users\DikS\Documents"
$DstDir = "D:\Backups\DikS\Docs"
XCopy "$SrcDir" "$DstDir\$(Get-Date -F yyyy-MM-dd)\" /S/Y >$Null
Please note, in order to run a PowerShell
script you may need to modify the execution policy on your system, the default setting is Restricted
.
You can do that by typing the following in an PowerShell Prompt, Run as Administrator: Get-ExecutionPolicy
, if Restricted
is returned, you can type Set-ExecutionPolicy RemoteSigned
and accept the prompt..