Reputation: 539
My lecturer gave the following as an in lecturer lab but i'm having trouble understanding how to do it. There are two scripts involved. The following is the first.
A9: Move the second batch script file into the “Processing” subfolder.
A10” Go to the root directory of the C: drive (This command must work the same from whichever drive, folder or subfolder the script is currently in.)
A11: Run the second batch script file.
A12: Update the folder search path for batch script file execution to include the “Processing” subfolder, and then display the folder search path. (Make sure you preserve the folders that were already in the search path.)
A13: Run the second batch script file again, by specifying only the file’s name.
how exactly would I do this.
what I don't understand is how you would get the batch script to run in any directory. In this case how would I be able to run the script from the root of the c drive when the script is located in the /processing file without specifying a path. I have looked into various thing including %~dp0 but I don't understand this.
Upvotes: 0
Views: 6737
Reputation: 19500
If you are using a windows 7 PC, you can set the path variable by hitting the windows key and searching for edit the system environment variables
;
If you are using an earlier version of windows then you can get to the System Properties by right clicking on the "My Computer" icon (Desktop and/or Start Menu) and selected "Properties"
Upvotes: 0
Reputation: 1120
In windows (and other OSes, including linux), the OS searches for executable files in directories specified by the global PATH variable. To see what is currently in that variable, in your CMD console type the following:
set PATH
If you want to add another folder to the path (as the instructions seem to say in A12), and to preserve the current folders, you would say
set PATH = %PATH%;C:/Some/Directory/Path
The %PATH% expands out to the old values, so you preserve them while adding something new. Under windows the separator may be a different character than ;
, but the principle should be the same. By adding your own folder to the folders searched for executable files, you can easily run a batch script in any folder without setting the full path.
Upvotes: 1
Reputation: 14304
If some folder is included in Path
env variable, files from there (batch scripts and exe among others) will be available from any directory.
Upvotes: 0