{"id":4984,"date":"2023-07-17T06:46:00","date_gmt":"2023-07-17T04:46:00","guid":{"rendered":"https:\/\/expert-only.com\/?p=4984"},"modified":"2023-09-19T12:49:37","modified_gmt":"2023-09-19T10:49:37","slug":"current-directory-path-with-cmd","status":"publish","type":"post","link":"https:\/\/expert-only.com\/en\/ms-dos\/current-directory-path-with-cmd\/","title":{"rendered":"How to display the current directory path with cmd?"},"content":{"rendered":"\n<h4 class=\"wp-block-heading has-text-align-left\"><strong><em>How to display the current directory path with cmd commands?<\/em><\/strong><\/h4>\n\n\n\n<p>Command to display the current directory path, which is the folder where a cmd prompt is currently running. The MS-DOS command prompt is a text-based user interface that allows you to interact with a Windows computer or server. In order to display the current directory path with cmd, use the MS-DOS cd command. When using batch files, it becomes much useful to reuse the current location path. Especially when scripting dynamic actions using variables.<\/p>\n\n\n\n\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_83 ez-toc-wrap-center counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/expert-only.com\/en\/ms-dos\/current-directory-path-with-cmd\/#1-display-the-current-directory-path-with-the-cd-command\" >1. Display the current directory path with the cd command<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/expert-only.com\/en\/ms-dos\/current-directory-path-with-cmd\/#2-use-the-current-directory-path-in-a-dos-variable\" >2. Use the current directory path in a DOS variable<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/expert-only.com\/en\/ms-dos\/current-directory-path-with-cmd\/#3-script-to-display-the-current-directory-path-dynamically\" >3. Script to display the current directory path dynamically<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/expert-only.com\/en\/ms-dos\/current-directory-path-with-cmd\/#4-display-the-cd-command-help\" >4. Display the cd command help<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\" id=\"h-1-display-the-current-directory-path-with-the-cd-command\"><span class=\"ez-toc-section\" id=\"1-display-the-current-directory-path-with-the-cd-command\"><\/span>1. Display the current directory path with the cd command<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The cd command is one of the most used commands in MS-DOS. It is used to change directories. This command can be used to navigate the directory structure and find files on a computer or a server. From the command prompt program called cmd.exe in the system, simply se the cd command.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bash\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><a href=\"https:\/\/expert-only.net\/windows\/ms-dos-commands\/display-the-current-directory-path-in-cmd\/attachment\/dos-command-line_cd-display-current-folder\/\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" src=\"https:\/\/expert-only.net\/wp-content\/uploads\/2022\/01\/dos-command-line_cd-display-current-folder.png\" alt=\"Display the current directory path with cmd using the cd command\" class=\"wp-image-2477\"\/><\/a><figcaption class=\"wp-element-caption\"><strong>Display the current directory path with cmd<\/strong><\/figcaption><\/figure>\n<\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"h-2-use-the-current-directory-path-in-a-dos-variable\"><span class=\"ez-toc-section\" id=\"2-use-the-current-directory-path-in-a-dos-variable\"><\/span>2. Use the current directory path in a DOS variable<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In a batch file it is a very similar approach, the difference is that the current directory name is stored like a system variable, with two percentage symbols. From a batch script, i.e., a .bat file.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bat\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">%cd%<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-3-script-to-display-the-current-directory-path-dynamically\"><span class=\"ez-toc-section\" id=\"3-script-to-display-the-current-directory-path-dynamically\"><\/span>3. Script to display the current directory path dynamically<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>For example, use this simple example to assign a batch variable with the current directory path and display it to the screen. To use this example, simply copy and paste the code below to a BATCH file, for example DisplayDirectory.bat and execute it.<\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bat\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">echo off\nrem the previous command is disabling echo to avoid all lines on the execution screen\n\nrem setting the variable with the current directory value\nset VarPath=%CD%\n\nrem displaying the variable on the prompt screen\necho \"The current folder is:\"\necho %VarPath%\n\nrem setting a 15 seconds timeout to let the prompt displayed\ntimeout 15<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"h-4-display-the-cd-command-help\"><span class=\"ez-toc-section\" id=\"4-display-the-cd-command-help\"><\/span>4. Display the cd command help<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The cd command is also useful to change the current drive and to navigate to the parent folder. To display the cd command help from within a command prompt, simply type this command: <\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"bat\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">cd \/?<\/pre>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"h-conclusion-on-displaying-the-current-windows-directory\">Conclusion on displaying the current Windows directory<\/h3>\n\n\n\n<p>It is available in MS-DOS, the Windows scripting tool. The syntax of the command is: cd [directory], where [directory] is the directory name or path to be changed to, i.e. the target. So this Windows tutorial explains how to get the current directory path with cmd. <strong>It is also possible to <a href=\"https:\/\/expert-only.com\/en\/ms-dos\/change-current-directory-with-cmd\/\">change the current directory to a new one with the cd command<\/a>.<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-embed aligncenter is-type-wp-embed is-provider-sql-and-it-tutorials wp-block-embed-sql-and-it-tutorials\"><div class=\"wp-block-embed__wrapper\">\n<blockquote class=\"wp-embedded-content\" data-secret=\"x1roCoWpfK\"><a href=\"https:\/\/expert-only.com\/en\/ms-dos\/change-current-directory-with-cmd\/\">Change the current directory with cmd<\/a><\/blockquote><iframe loading=\"lazy\" class=\"wp-embedded-content\" sandbox=\"allow-scripts\" security=\"restricted\" style=\"position: absolute; clip: rect(1px, 1px, 1px, 1px);\" title=\"&#8220;Change the current directory with cmd&#8221; &#8212; SQL and IT Tutorials\" src=\"https:\/\/expert-only.com\/en\/ms-dos\/change-current-directory-with-cmd\/embed\/#?secret=SdMAhVLuz6#?secret=x1roCoWpfK\" data-secret=\"x1roCoWpfK\" width=\"500\" height=\"282\" frameborder=\"0\" marginwidth=\"0\" marginheight=\"0\" scrolling=\"no\"><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>How to display the current directory path with cmd commands? Command to display the current directory path, which is the folder where a cmd prompt is currently running. The MS-DOS command prompt is a text-based user interface that allows <a class=\"mh-excerpt-more\" href=\"https:\/\/expert-only.com\/en\/ms-dos\/current-directory-path-with-cmd\/\" title=\"How to display the current directory path with cmd?\">&#8230;<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":5657,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[410],"tags":[412,418,414],"class_list":{"0":"post-4984","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-ms-dos","8":"tag-batch","9":"tag-folder","10":"tag-script"},"_links":{"self":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/4984","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/comments?post=4984"}],"version-history":[{"count":3,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/4984\/revisions"}],"predecessor-version":[{"id":27033,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/posts\/4984\/revisions\/27033"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media\/5657"}],"wp:attachment":[{"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/media?parent=4984"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/categories?post=4984"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/expert-only.com\/en\/wp-json\/wp\/v2\/tags?post=4984"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}