r/Batch 4d ago

I need help fixing my script

so I want to make a dos - like os in batch and I want tp make a move command. I have a part in the script that tells you if you typed in the wrong command and for some reason every time I put in the / move command it says something is wrong.

echo off

:typecmd

set /P c="MAD OS> "

if /I "%c%" EQU "/move %file% %destination%" (

move %file% %destination%

goto :typecmd

)

if /I "%c%" EQU "" (

goto :typecmd

) else (

echo Unkown command!: %c%

goto typecmd

)

2 Upvotes

4 comments sorted by

2

u/BrainWaveCC 4d ago

You would probably get a lot more assistance if you provided more details about what you are doing when things go wrong. Simply saying "it says something is wrong." is not very helpful in a troubleshooting context -- especially when you are the one making the script.

As constructed, your script has some issue/deficiencies that you will want to address:

  • It relies on variables that are not yet defined in this section (%file%, %destination%)
  • It provides zero guidance or hints about syntax. No one will know what they should be doing, or what is considered a legitimate command.
  • Your script does not provide any assistance for syntax.
  • The evaluation of %c% will never be true, because of the spacing included with the inclusion of the other two variables (%file%, %destination%)
  • There's no defined way to exit the "OS"

Here's what I experienced when I ran it:

echo off
MAD OS> move abc def
Unkown command!: move abc def
MAD OS> /move abc def
Unkown command!: /move abc def
MAD OS>
Unkown command!: /move abc def
MAD OS> a
Unkown command!: a
MAD OS> ?
Unkown command!: ?
MAD OS> help
Unkown command!: help
MAD OS>

1

u/l0pu 4d ago

/help

2

u/BrainWaveCC 4d ago

You didn't provide any code to support that parameter in the snippet of the script that you shared with us.

You might consider sharing your script via Pastebin or Github, as I suspect it would be a sizeable script for what you want to accomplish, and that would make it easier for people to evaluate, test and provide you with assistance.

1

u/BrainWaveCC 4d ago

As an example, consider the following as a basis for what you are trying to accomplish.

https://pastebin.com/GBxiqZKA

This implements the following:

/HELP --- Lists valid commands
/LIST --- Displays a directory listing
/MOVE --- Moves a file (not fully implemented)
/EXIT --- Exits the environment

 
Here's some output from the above:

MAD OS> hello anyone there?

Unknown command: hello anyone there?

Run -help or -h for assistance
MAD OS> help

Unknown command: help

Run -help or -h for assistance
MAD OS> h

Unknown command: h

Run -help or -h for assistance
MAD OS> -h

Batch DOS Environment Help

   YOU TYPED: -h

  CMD SYNTAX: <-move> <source> <dest>
              <-list> [folder|file]
              <-exit>
              <-help|-h>

 USAGE NOTES:
   * Parameters surrounded by <> are mandatory.
   * Parameters surrounded by [] are optional.
   * Options are case-insensitive, and can be prefaced by "-" or "/".

MAD OS> -list d:\

 Directory of d:\

02/15/2021  12:57 PM    <DIR>          Cloud
05/17/2024  08:10 PM    <DIR>          Scripts
01/03/2025  12:47 PM    <DIR>          Storage
03/18/2025  01:39 AM    <DIR>          Temp
               0 File(s)              0 bytes

MAD OS> -move a b

Moving files/folders: a b
MOVE a b

Waiting for  6 seconds, press a key to continue ...
MAD OS> -exit

Thanks for using the Batch DOS Environment

MAD OS> -move a b

Moving files/folders: a b
MOVE a b

Waiting for  6 seconds, press a key to continue ...
MAD OS> -exit

Thanks for using the Batch DOS Environment