% Cd % and % ~ in DOS batch processing ~ Analysis of dp0 Similarities and Differences

Source: Internet
Author: User

In DOS batch processing, you sometimes need to know the current path. In DOS, two environment variables can be related to the current path. One is % cd %, and the other is % ~ Dp0.

The usage and content of these two variables are different.

1.% cd % can be used in batch files or in command lines. After expansion, it is the drive letter: + current directory. For example, enter c in the dos window: under the \ dir directory,

Input: echo % cd %, displayed as: c: \ dir.
The content of % cd % can be changed. The content is the command execution path or the execution path of the batch file.

2.% ~ Dp0 can only be used in batch files. It is determined by the directory location of the batch files it is located in. It is the drive letter of the batch files: + path. During the execution of this batch file, the expanded content cannot be changed. For example, there is a batch processing file named path. bat in disk D, whose content is:Copy codeThe Code is as follows: @ echo off
Echo this is % cd %
Echo this is % ~ Dp0 % ~ Dp0

Run it in C: \ and E: \ respectively, and the output is:

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.