Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: %~dp0 vs %cd%  (Read 464305 times)

0 Members and 2 Guests are viewing this topic.

djshoxxx



    Newbie

    • Experience: Experienced
    • OS: Windows 7
    Re: %~dp0 vs %cd%
    « Reply #30 on: December 18, 2019, 01:40:12 AM »
    I was trying to understand what @pushd "%~dp0" ment, I googled it, and now I understand it because of this thread. Only 14 days from 2020 lol!

    thank you, contributors to this post, and a posthumous thank you and RIP to foxidrive

    patio

    • Moderator


    • Genius
    • Maud' Dib
    • Thanked: 1769
      • Yes
    • Experience: Beginner
    • OS: Windows 7
    Re: %~dp0 vs %cd%
    « Reply #31 on: December 18, 2019, 05:56:01 AM »
    RIP...
    " Anyone who goes to a psychiatrist should have his head examined. "

    croger1998



      Newbie
      • Experience: Expert
      • OS: Mac OS
      Re: %~dp0 vs %cd%
      « Reply #32 on: December 19, 2019, 08:11:48 AM »
      I have been around PCs all my life. I have been in IT for 20+ years and have never came across %~dp0 before. No idea why. I am glad I came across this post to better understand this hidden gem.

      Thanks for the info everyone.


      martosio



        Newbie

        • Experience: Beginner
        • OS: Unknown
        Re: %~dp0 vs %cd%
        « Reply #33 on: December 31, 2019, 07:27:02 PM »
        This thread helped me about two years ago (august 2018 @ WTD), but due to thread policy I head to wait until 2020 to reply ;)

        Thanks guys!!

        Caldor



          Newbie

          • Experience: Experienced
          • OS: Windows 10
          Re: %~dp0 vs %cd%
          « Reply #34 on: August 05, 2020, 07:54:58 AM »
          It's been 4 years...
          It's been... another 4 years...  ;D

          I using a MiSTer FPGA to run a DOS core, and looking into batch scripting, but just cannot figure out how to get the path to the currently active directory.

          I cannot get %~dp0 to work either... but trying to experiment some more. I am trying with FreeDOS, DOS 6.22 and DOS 7.1. But I guess I have to make sure I did try all of them.

          BC_Programmer


            Mastermind
          • Typing is no substitute for thinking.
          • Thanked: 1140
            • Yes
            • Yes
            • BC-Programming.com
          • Certifications: List
          • Computer: Specs
          • Experience: Beginner
          • OS: Windows 11
          Re: %~dp0 vs %cd%
          « Reply #35 on: August 05, 2020, 01:51:29 PM »
          %~dp0 and things like %cd% are part of the NT Extensions that were added to the command prompt with Windows NT4.

          the "cd" command by itself outputs the current directory, but I don't know a way you can get that into an environment variable without utilizing things like QBASIC.
          I was trying to dereference Null Pointers before it was cool.

          patio

          • Moderator


          • Genius
          • Maud' Dib
          • Thanked: 1769
            • Yes
          • Experience: Beginner
          • OS: Windows 7
          Re: %~dp0 vs %cd%
          « Reply #36 on: September 10, 2020, 05:17:16 PM »
          Somehow i knew in the back of my mind it would be Dias ressurecting this one...

          Who is that masked man ? ?
          " Anyone who goes to a psychiatrist should have his head examined. "

          Sam_Weller



            Starter

            • Experience: Beginner
            • OS: Unknown
            Re: %~dp0 vs %cd%
            « Reply #37 on: September 30, 2020, 11:51:58 AM »

            guys help me out?

            You are not the "former Dias de Verano".

            Allan

            • Moderator

            • Mastermind
            • Thanked: 1260
            • Experience: Guru
            • OS: Windows 10
            Re: %~dp0 vs %cd%
            « Reply #38 on: September 30, 2020, 05:34:06 PM »
            Hey Mike, hope all is well. Good to see you back.

            Nathansswell



              Rookie

              Thanked: 1
              • Yes
              • I make music!
            • Certifications: List
            • Computer: Specs
            • Experience: Beginner
            • OS: Windows 8
            Re: %~dp0 vs %cd%
            « Reply #39 on: November 14, 2021, 02:50:16 PM »
            We can forget about 2020 right

            Sam_Weller



              Starter

              • Experience: Beginner
              • OS: Unknown
              Re: %~dp0 vs %cd%
              « Reply #40 on: November 27, 2021, 02:40:05 AM »
              It's been... another 4 years...  ;D

              I using a MiSTer FPGA to run a DOS core, and looking into batch scripting, but just cannot figure out how to get the path to the currently active directory.

              I cannot get %~dp0 to work either... but trying to experiment some more. I am trying with FreeDOS, DOS 6.22 and DOS 7.1. But I guess I have to make sure I did try all of them.

              Resurrection time!

              Works with MS-DOS 7 and I have no reason to think it won't work with (say) 6.22

              Code: [Select]
              @echo off
              >temp1.bat echo @PROMPT SET _CD=$P
              >temp2.bat command /c temp1.bat
              call temp2.bat
              del temp1.bat
              del temp2.bat
              echo currentDir=%_CD%