SomethingToChatWith Posted March 18, 2009 Share Posted March 18, 2009 Alright so with commands like diskpart I've wondered how you could create a batch file to preform actions with x command. I know you couldn't just put say something like "list disk" right after diskpart in the actual batch, so I did end up finding a few sites on google on the topic. Here's a sample batch I'm having some trouble understanding fully. It basically takes two partitions by number as referenced with diskpart's list part command and switches thier drive letter assignments with each other. Not really useful and not exactly what I want/need, but anyway... @for /f "tokens=3" %%x in ('echo list volume ^| diskpart ^| findstr /c:"Volume %1"') do set v1=%%x @for /f "tokens=3" %%x in ('echo list volume ^| diskpart ^| findstr /c:"Volume %2"') do set v2=%%x echo select volume %1 > SwitchDisks.csp echo remove letter %v1% noerr >> SwitchDisks.csp echo select volume %2 >> SwitchDisks.csp echo remove letter %v2% noerr >> SwitchDisks.csp echo select volume %1 >> SwitchDisks.csp echo assign letter %v2% >> SwitchDisks.csp echo select volume %2 >> SwitchDisks.csp echo assign letter %v1% >> SwitchDisks.csp diskpart /s SwitchDisks.csp del SwitchDisks.csp I know that its echoing all the actions to preform inside diskpart to another file to use with diskpart's script switch (/s). Lines 1 and 2 are what I really don't get and things like %v1, %v2, etc though. Explaination any one? Quote Link to comment Share on other sites More sharing options...
Bit Hunter Posted March 18, 2009 Share Posted March 18, 2009 Put the code in a batch file, and call for it with two arguments. %x is a argument. Where x is the position. Put this in a batch file: @echo off echo %1 echo %2 echo %3 echo %4 echo %* call it by: <name>.bat arg1 arg2 arg3 arg4 arg5 Here is more in details: http://commandwindows.com/batch.htm In your case you need to send the volume number args to script. Quote Link to comment Share on other sites More sharing options...
SomethingToChatWith Posted March 18, 2009 Author Share Posted March 18, 2009 I've made up a couple batch files in my day. I'm familar with %1 %2 %3 etc for passed in parameters. Its the %v1 %v2 etc and the first two lines that are throwing me off. Quote Link to comment Share on other sites More sharing options...
Bit Hunter Posted March 18, 2009 Share Posted March 18, 2009 for /f "tokens=2" %x in ('echo list volume ^| diskpart ^| findstr /c:"Volume"') do set v1=%x this will give you all the options you have available... Quote Link to comment Share on other sites More sharing options...
SomethingToChatWith Posted March 19, 2009 Author Share Posted March 19, 2009 I kind of understand your explaination, but want to know what its doing behind the scenes detail by detail, command by command... Questions: Whats the /f swtich for for "for"? How can diskpart run without /s for "list volume" which is echoed before it without using a file? Whats the ' for before "echo"? I guess its incrementing v<number> variables for each volume line returned using findstr on the output from diskpart list volme, but what are the ^'s for? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.