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

Author Topic: %~dp0  (Read 5103 times)

0 Members and 1 Guest are viewing this topic.

NEILD

    Topic Starter


    Rookie

    %~dp0
    « on: February 10, 2011, 04:16:55 AM »
    Hi,

    I'm a novice at this at DOS...I'm required about once a year to look at it...so please explain in very simple terms...

    I have some code in front of me :
    set CONVERT=%~dp0

    I've read something about it finding a path...but don't quit follow it...
    The .cmd it is part of is in the following folder:
    D:\prog\pdms\v10.0\plot\convert

    So my first question is what does this do set "CONVERT=%~dp0" ?

    - -----------------------------------------------------------------------------

    I also have this :

    call "%TEMP%\%~nx1.pdf.cmd"

    I understand the call part and %TEMP% is a stored variable (expanding to a folder)...
    It's this part that I don't understand :
    \%~nx1.pdf.cmd
    There are other .cmd in the folder and I think this is refering to one..
    So I think it's only this part that is of interest:
    \%~nx1.

    - -----------------------------------------------------------------------------

    And finally this :
    -sOutputFile="%~dpn1.pdf"

    Particulaly :
    %~dpn1

    Hope someone can help

    Regards
    neil


    Salmon Trout

    • Guest
    Re: %~dp0
    « Reply #1 on: February 10, 2011, 06:17:17 AM »
    %0, %1 to %9 are "replaceable parameters". %0 is a special one - it expands to the name of the batch file itself.

    %1 is the first parameter passed to the batch file from the command line or from another batch, %2 is the second one, and so on up to %9 (the highest possible).

    Thus if you type

    mybatch.bat cat dog "horse and cart" then in mybatch.bat, when it runs, %1 will expand to cat, %2 will expand to dog, and %3 will expand to "horse and cart"

    The parameters can be modified using the same variable modifiers as FOR variables, for full documentation see the FOR help which you get by typing FOR /? at the prompt

    They relate to files so that if %1 is a filename then %~d1 is a drive e.g. C: and %~p1 is the path, %~n1 the name, %~x the extension. They can be combined e.g. %~dpnx1

    for example %~dp0 contains the drive and path of the batch file itself





    « Last Edit: February 10, 2011, 06:30:54 AM by Salmon Trout »