batch files and drive letters

Discussion in 'Software' started by hacker183, Oct 15, 2009.

  1. hacker183

    hacker183 Private E-2

    i have a set of apps that i use 10-15 time a day (i install them back to back) so i made a batch file to install them and put it (and the apps) on a flash driver.

    from time to time the driver letter of the flash drive is not E: so ever thing is not on E:\ there D:\ or F:\ or WHATEVER:\

    so the quston is what is the batch variable so it goes to "USB that has the .bat\apps\run this\ect..."


    Thanks for any help
     
  2. GermanOne

    GermanOne Guest

    Hi hacker183.

    The own call of your batch file is in %0. So if you need only the drive letter you can find it in %~d0.
    Code:
    @echo off &setlocal
    echo my own drive: %~d0
    pause
    
    regards
    GermanOne
     
  3. hacker183

    hacker183 Private E-2

    thank you thats what i need
     
  4. hacker183

    hacker183 Private E-2

    ok so its not what i was needing but it helps... I need some way to see the full path that the bat is started in so if its in "C\apps\auto install\my.bat" or if its on a flash driver at "D:\the new app\other\more other" it will fix it so its all good...

    thanks again...
     
  5. red death68

    red death68 Command Sergeant Major

    well a less efficient way is to skip the drive letter so it looks like

     
  6. hacker183

    hacker183 Private E-2

    aaahhh ok I thought you had to have a driver letter and a full path to start anything... i can just have a file structure with the batch at top.. ok thanks a lot.:)
     
  7. red death68

    red death68 Command Sergeant Major

    ya just some portable apps that are self contained wont run with start option like my opera browser

    but it should work pretty good
     
  8. GermanOne

    GermanOne Guest

    Hi guys,

    if you've got a parameter variable like %0, you can use
    %~d0 for the directory
    %~p0 for the path
    %~n0 for the name
    %~x0 for the extension
    and it's also possible to use a combination.

    So if you need the whole path (directory and path) of your batch file you have to use %~dp0 . red death68's way isn't really safe.

    regards
    GermanOne
     
  9. red death68

    red death68 Command Sergeant Major

    why isnt it safe?
     
  10. GermanOne

    GermanOne Guest

    Hi red death68.

    The reason is that your solution is "relative" and not "absolute". You always have to watch up where you are. That means if you changed the working directory using CD /D or PUSHD, it doesn't work. The content of %0 never changed.
    But you are right, with high probability it will work for hacker183.

    regards
    GermanOne
     
  11. hacker183

    hacker183 Private E-2

    Ok thanks for all the help and red's way works but I'm going to use the parameter variables just to keep it clean thanks for every thing.
     

MajorGeeks.Com Menu

Downloads All In One Tweaks \ Android \ Anti-Malware \ Anti-Virus \ Appearance \ Backup \ Browsers \ CD\DVD\Blu-Ray \ Covert Ops \ Drive Utilities \ Drivers \ Graphics \ Internet Tools \ Multimedia \ Networking \ Office Tools \ PC Games \ System Tools \ Mac/Apple/Ipad Downloads

Other News: Top Downloads \ News (Tech) \ Off Base (Other Websites News) \ Way Off Base (Offbeat Stories and Pics)

Social: Facebook \ YouTube \ Twitter \ Tumblr \ Pintrest \ RSS Feeds