[W7] Batchfile op drive met variabele driveletter

Pagina: 1
Acties:

Acties:
  • 0 Henk 'm!

  • mirelia
  • Registratie: Mei 2002
  • Laatst online: 10-03 19:07
Ik heb een batchbestand op een USBstick waarin 1 file van de stick naar een dir op C wordt gekopieerd en een lijst met .regkeys waar er 1 van gestart moet worden.
bijv:
copy K:\xxx\xxx.bmp c:\xxx
start /b "xxx" "K:\xxx\xxx.reg"

Nu is K op mijn PC de USBstick maar op een andere PC misschien weer E
Hoe kan ik nou de batchfile zo maken dat het altijd werkt ondanks de wisselende driveletters?
De batchfile gaat alleen op Windows7 systemen gestart worden

Acties:
  • 0 Henk 'm!

  • SkiFan
  • Registratie: Juli 2001
  • Laatst online: 22:08
In batch zou je een if exist kunnen doen. Dan kun je de driveletters aflopen.

Nonsensical line goes here <---


Acties:
  • 0 Henk 'm!

  • anandus
  • Registratie: Februari 2001
  • Niet online
Als het de schijf is waar Windows op staat kan je ook %SystemDrive% gebruiken :)

Edit: Oh, het gaat om bepalen wat de usb-schijf is? Kan je dan niet beter relatieve mappen gebuirken? :)

[ Voor 41% gewijzigd door anandus op 08-11-2009 18:36 ]

"Always remember to quick save" - Sun Tzu


Acties:
  • 0 Henk 'm!

  • mirelia
  • Registratie: Mei 2002
  • Laatst online: 10-03 19:07
anandus schreef op zondag 08 november 2009 @ 18:35:
Als het de schijf is waar Windows op staat kan je ook %SystemDrive% gebruiken :)

Edit: Oh, het gaat om bepalen wat de usb-schijf is? Kan je dan niet beter relatieve mappen gebuirken? :)
Misschien wel, maar hoe ziet dat er in de praktijk uit dan?
Ik ben nogal een leek hierin

Acties:
  • 0 Henk 'm!

  • anandus
  • Registratie: Februari 2001
  • Niet online
mirelia schreef op zondag 08 november 2009 @ 18:38:
[...]

Misschien wel, maar hoe ziet dat er in de praktijk uit dan?
Ik ben nogal een leek hierin
The Basics of Batch Programming
Kijk hier eens, daar staat het tussen :)
Relative Paths
Although many people know the cd and md commands, it is not that common to use relative path names in DOS that much. The path names are called relative because they are specified relative to the current directory (.)). Here are some examples:

cd games\duke3d
Will change to .\games\duke3d where . is the current directory. It is not necessary to type
cd games
cd duke3d
separately, but on the other hand this means less re-typing if you make a mistake. I'd suggest using complete pathnames as much as possible to decrease the number of lines in your batch scripts, though.

Notice that
md games\mygame
Doesn't work as you would expect, unless you have NT command extensions on but that's another story.

Another way of using relative paths is to refer to directories that are on a lower level on the directory hierarchy. Say we are in \temp
copy ..\autoexec.bat .
Will copy autoexec from the root directory to the subdir temp. This can also be risky, don't ever type del . in temp like I once did. The two periods can be chained like this ..\..\..\ to refer to even lower levels on the directory tree. You can also continue directory specifications after a period. Supposing we are in \games\dukebacup
xcopy /s ..\duke3d\* .
Will copy everything under \games\duke3d to \games\dukebackup including sub-directories. Notice that \games\duke3d is actually also a relative path name (it's relative to the current drive).

[ Voor 67% gewijzigd door anandus op 08-11-2009 18:42 ]

"Always remember to quick save" - Sun Tzu


Acties:
  • 0 Henk 'm!

  • mirelia
  • Registratie: Mei 2002
  • Laatst online: 10-03 19:07
Ok thx....ik ga me er even in verdiepen

Acties:
  • 0 Henk 'm!

  • anandus
  • Registratie: Februari 2001
  • Niet online
mirelia schreef op zondag 08 november 2009 @ 18:42:
[...]

Ok thx....ik ga me er even in verdiepen
Zie mijn edit, en vooral het cursieve :)

"Always remember to quick save" - Sun Tzu


Acties:
  • 0 Henk 'm!

  • mirelia
  • Registratie: Mei 2002
  • Laatst online: 10-03 19:07
Kijk...je bent nooit te oud om te leren. :) Dit was de oplossing voor mij
Pagina: 1