0

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.

Machavity
  • 28,730
  • 25
  • 78
  • 91
allies4ever
  • 111
  • 2

1 Answers1

1

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.

unclemeat
  • 4,691
  • 4
  • 22
  • 49
  • 1
    Note that `%date%` always comes back in your system's short date format, which is not only configurable by the user but has different defaults in different regions (on my system, your echo command produces `2015-04-16`). If you need something portable, see http://stackoverflow.com/questions/10945572/windows-batch-formatted-date-into-variable. Basically you need to use something other than batch (eg: wmic, vba, powershell, etc) – Ryan Bemrose Apr 17 '15 at 00:02