문제

현재 작업 디렉토리의 전체 경로를 얻는 데 사용할 수있는 Windows 명령 행 명령이 있습니까?

또한 배치 파일에 사용되는 변수 안에이 경로를 어떻게 저장할 수 있습니까?

도움이 되었습니까?

해결책

사용 cd 쉘을 직접 사용하는 경우 논쟁이 없습니다. %cd% 배치 파일로 사용하려면 환경 변수처럼 작동합니다).

다른 팁

다음과 같이 배치/환경 변수를 설정할 수 있습니다.

SET var=%cd%
ECHO %var%

Windows 7 x64 cmd.exe의 샘플 스크린 샷.

enter image description here

업데이트: 당신이 할 경우 SET var = %cd% 대신에 SET var=%cd% , 아래는 일어나는 일입니다. Jeb에게 감사합니다.

enter image description here

배치 파일에서 현재 디렉토리 캡처

Windows 도움말을 인용하십시오 set 명령 (set /?):

If Command Extensions are enabled, then there are several dynamic
environment variables that can be expanded but which don't show up in
the list of variables displayed by SET.  These variable values are
computed dynamically each time the value of the variable is expanded.
If the user explicitly defines a variable with one of these names, then
that definition will override the dynamic one described below:

%CD% - expands to the current directory string.

%DATE% - expands to current date using same format as DATE command.

%TIME% - expands to current time using same format as TIME command.

%RANDOM% - expands to a random decimal number between 0 and 32767.

%ERRORLEVEL% - expands to the current ERRORLEVEL value

%CMDEXTVERSION% - expands to the current Command Processor Extensions
    version number.

%CMDCMDLINE% - expands to the original command line that invoked the
    Command Processor.

참고 %CD% - expands to the current directory string. 부분.

유닉스에서?

Pwd

이것은 항상 나를 위해 일했습니다.

SET CurrentDir="%~dp0"

ECHO The current file path this bat file is executing in is the following:

ECHO %CurrentDir%

Pause

창문의 경우 사용할 수 있습니다

cd

그리고 Linux의 경우

pwd

명령이 있습니다.

창문의 경우 cd 그 자체로는 현재 작업 디렉토리를 보여줄 것입니다.

UNIX 및 WARKALIKE 시스템의 경우 pwd 동일한 작업을 수행합니다. 당신은 또한 사용할 수 있습니다 $PWD 일부 쉘 아래의 쉘 변수. Windows가 쉘 변수를 통해 현재 작업 디렉토리를 얻는 것을 지원하는지 확실하지 않습니다.

Windows :

chdir 현재 디렉토리의 이름을 표시하거나 변경합니다.

Linux에서 :

Pwd 현재 디렉토리의 이름을 표시합니다.

CHDIR 게시물에 대한 의견에 후속 질문 (변수에 데이터 저장)을 기반으로 디렉토리를 변경 한 후 현재 경로를 저장하려고합니다.

원래 사용자는 디렉토리를 변경하고 "POPD"로 복원 할 수있는 스택으로 현재 디렉토리를 푸시하는 "Pushd"를 살펴 봐야합니다. 모든 최신 Windows CMD 쉘에서 배치 파일을 만들 때가는 길입니다.

현재 경로를 잡아야한다면 최신 CMD 쉘에는 % CD % 변수가있어 다른 변수에서 참조 할 수 있습니다.

@for /f "usebackq" %%x in (`chdir`) do set var=%%x
@echo "The currenct directory is: %var%"

하지만, 물론이야, gmaran23의 대답은 훨씬 쉬운 일입니다.

a .bat 아래에 파일 System32, 이름을 지정하겠습니다 copypath.bat 현재 경로를 복사하라는 명령 할 수 있습니다:

echo %cd% | clip

설명:

%cd% 현재 경로를 줄 것입니다

CLIP

Description:
    Redirects output of command line tools to the Windows clipboard.
    This text output can then be pasted into other programs.

Parameter List:
    /?                  Displays this help message.

Examples:
    DIR | CLIP          Places a copy of the current directory
                        listing into the Windows clipboard.

    CLIP < README.TXT   Places a copy of the text from readme.txt
                        on to the Windows clipboard.

지금 copyclip 어디에서나 사용할 수 있습니다.

Windows 명령 프롬프트에서 chdir 또는 cd 콘솔에서 현재 작업 디렉토리의 전체 경로를 인쇄합니다.

경로를 복사하려면 다음을 사용할 수 있습니다. cd | clip.

창에서 유형 cd 작업 전류 경로의 경우.

Linux에서 pwd 현재 작업 경로.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top