2

When I need to extract a .RAR file using a BAT script I use the following command:

set path="path\to\installed\winrar\directoy"
WinRAR x "name of file.RAR"

In the next line if I try to give a xcopy command it says:

'xcopy' is not recognized as an internal or external command, operable program, or batch file.

Whereas if I run the xcopy command before issuing the set path command, it works without any issue.

How do I use the xcopy command AFTER giving the set path command?

MLavoie
  • 9,671
  • 41
  • 36
  • 56
AwesomeVk47
  • 73
  • 1
  • 5
  • 2
    because you broke the default `path` variable. rename the viariable to `mypath` like so `set "mypath=path\to\installed\winrar\directoy"` also notice the location of my double quotes. – Gerhard Jul 09 '20 at 10:00
  • 1
    Don't use `path` as a variable name. `%path%` tells the command prompt where to find it's executables (like `xcopy.exe`). Open a new command prompt and type `set`. Don't mess with any variables listed (unless you know exactly what you do, what they are for and how changing them influences your system) – Stephan Jul 09 '20 at 10:04
  • 3
    At the end of `set /?` are some more variables listed, you shouldn't mess around with. – Stephan Jul 09 '20 at 10:14

1 Answers1

2

To better explain this in more detail.

Windows has environment variables for both System and User. one of these variables is path.

Path is used as a default indexing variable which tells the system where to find files and executables. So for you setting path, your cmd prompt no longer knows where to find the executables, unless you supply the full path to the executable BUT it should still never be done.

To understand it better: open cmd and type set path or echo %path% and see the result.

Then do set "path=some string" then do set path or echo %path% again and notice how it changed.

So get to know your variables by running set from cmd to list all default variables, and ensure you do not use any of them when creating variables in batch-files. It can become VERY dangerous.

So, to wrap it up, to fix your issue, change path to something unique like mypath:

set "mypath=path\to\installed\winrar\directoy"
"%mypath%\WinRAR.exe" x "name of file.RAR"
Gerhard
  • 22,678
  • 7
  • 27
  • 43