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.

1
  • "do something at a certain date" cries for a scheduled task. Take a look to Task Scheduler. Commented Aug 4, 2018 at 15:56

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

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 stackoverflow.com/questions/10945572/…. Basically you need to use something other than batch (eg: wmic, vba, powershell, etc)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.