Use relative paths in the batch processing (. BAT) File

Source: Internet
Author: User

Generally, when the relative path of the batch processing file is processed, the starting position is the directory where the BAT file is located. For example, execute the BAT file in the D: \ XX directory, all operations on relative directories are executed under D: \ xx.

However, some commands require administrator permissions. Right-click and choose c: \ windows \ system32 as the administrator, which is not what we want at this time,

One solution is to add "cd d: \ xx" at the beginning of the batch processing line to enter the directory to modify its current location, however, you need to add an absolute path to the batch processing file. If you move the BAT file to another location, it cannot be used. In this case, a better way is to use "CD/d % ~ Dp0 "instead of" cd d: \ xx ".

To sum up, when writing a BAT file, you 'd better add "CD/d % ~ Dp0 "to unify the initial directory of the file.

For example, if auto. bat is in the folder D: \ my_bat \, the content of auto. bat is as follows:

CD/d % ~ Dp0
Start MDF-API \ feedserver \ feedserverv1_3.exe

To start the program D: \ my_bat \ MDF-API \ feedserver \ feedserverv1_3.exe

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.