samosaman
samosaman

Reputation: 111

Move batch file on specific date

I'm new to batch. I want to move a file hello.bat to the startup folder, but only on a specific date.

How do I insert "if then" statements (e.g. If "date" Then "execution")?

Furthermore, how do I move a file?

I've tried this using what I've gathered from Google:

If %date% NEQ 2015/12/25 goto asdf 
move c:\Users\USERNAME\AppData\hello.bat
c:\Users\USERNAME\AppData\Roaming\Microsoft\Windows\Start
Menu\Programs\Startup
:asdf

It doesn't seem to be working, however - the move part works fine, but when I insert the If statement, it doesn't compile.

Can someone offer me a solution to this problem? I feel I would learn more from an example than reading something online.

Upvotes: 0

Views: 668

Answers (1)

unclemeat
unclemeat

Reputation: 5197

The %date% variable is different depending on your system settings. To check the format of %date%, run the following command in a cmd window echo %date%.

In my system, the date format is Day 00/00/0000. So the following would be needed (string manipulation to remove the first four characters of the date).

if "%date:~4%" NEQ "12/25/2015" goto asdf

As a side note; you can simply goto :EOF (End Of File) if you just want the script to end.

Upvotes: 1

Related Questions