shk86 Posted March 22, 2010 Posted March 22, 2010 any body plz guide me for this command for use in windows post installer.(for /f "delims=: tokens=1" %%i in ("%~dp0") do set drive=%%i:)I M RUNNING IT ON WPI.CMD AND SUCCESFULLY RUNNING WPI AFTER WINDOWS INSTALLATION.BUT I HAVE COPIED IT THROUGH A FORUM.I NEED TO UNDERSTAND IT PROPERLY HOW IT WORKS WHAT DOES (/F) (DELIMS= (TOKENS=1) %%i (%~dp0) stands for .plz help maintaing my knowledgethanks
uid0 Posted March 22, 2010 Posted March 22, 2010 for /f "delims=: tokens=1" %%i in ("%~dp0") do set drive=%%i:delims is short for delimiters, these divide the output into tokens (pieces).tokens=1 means we only want the first token.%%i is the variable that gets set to the first token.%~dp0 is the drive and path of the currently running script.What the line does is to set the variable %drive% to be just the letter of the drive that the current script is running from, which could probably be simplified to justset drive=%~d0For more info try typing for /? set /?call /?at a command prompt, or try this site.
firefox99 Posted March 23, 2010 Posted March 23, 2010 can we use this short command set drive=%~d0instead of it??how to run wpi after windows installation through a batch and auto run file
shk86 Posted March 23, 2010 Author Posted March 23, 2010 thxx 4 ur reply..i have understood it clearly bt u havnt tell what /f stands for ..and will the cd drive will be automatically recognize through this command or we had to add some more text.?? plzzz do reply thxx
Guest Posted March 23, 2010 Posted March 23, 2010 (edited) I don't see why not, firefox99.The optical drive should be recognized automatically, shk86. I'm not certain what the /f stands for, but third-party documentation does exist. Edited March 23, 2010 by 5eraph
jaclaz Posted March 23, 2010 Posted March 23, 2010 Read here:FORWindows NT 4/2000/XP Syntaxhttp://www.robvanderwoude.com/ntfor.phpFOR /Ftokens and delimsStep by stephttp://www.robvanderwoude.com/ntfortokens.phpjaclaz
firefox99 Posted March 24, 2010 Posted March 24, 2010 for f/ is to Loop through items in a text file and to Loop through the output of a command.
shk86 Posted March 24, 2010 Author Posted March 24, 2010 thxx alot uido,5eraph,jaclaz,for ur support and od course firefox99 but i realy didnt understand it clearly yet.ill b thankfull if u explain a little more...thxxx guyzz.
jaclaz Posted March 24, 2010 Posted March 24, 2010 Let's try playing the game the other way round. You originally asked about this:for /f "delims=: tokens=1" %%i in ("%~dp0") do set drive=%%i:Try putting it, slightly modified in a batch like this and sabe the batch as C:\Batches\forf.cmd:@ECHO OFFfor /f "tokens=1,2,3 delims=:\" %%i in ("%~dp0") do (ECHO this is "i" i.e. token #1 "%%i"ECHO this is "j" i.e. token #2 "%%j"ECHO this is "k" i.e. token #3 "%%k"ECHO this is parameter 0, i.e. the command line that started the batch "%0"ECHO this is parameter ~d0, i.e. the Drive of command line that started the batch "%~d0"ECHO this is parameter ~dp0, i.e. the Drive and Path of command line that started the batch "%~dp0"set drive=%%i:)SET driveand run it:C:\batches>forfthis is "i" i.e. token #1 "C"this is "j" i.e. token #2 "batches"this is "k" i.e. token #3 ""this is parameter 0, i.e. the command line that started the batch "forf"this is parameter ~d0, i.e. the Drive of command line that started the batch "C:"this is parameter ~dp0, i.e. the Drive and Path of command line that started the batch "C:\batches\"drive=C:C:\batches>Now, you should have understood, and you can change the original snippet to:for /f %%i in ("%~d0") do set drive=%%iwhich is a simplified version, or go all the way and use:SET drive=%~d0which is the normal way to find out the drive from which a batch is started.In other words, the original problem posted needs not the use of FOR or of FOR /F.jaclaz
firefox99 Posted March 24, 2010 Posted March 24, 2010 o u rock jaclaz i understood it clearly .many regards to u...i have 1 more thing to ask suppose i have a folder on desktop "wpi" containing wpi.hta in it and $oem$ folder beside wpi folder containing runwpi batch file. could the same command will b used for opening the wpi.hta.for /f "delims=: tokens=1" %%i in ("%~dp0") do set drive=%%i:set wpipath=%drive%\wpiSET KEY=HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnceExREG ADD %KEY%\999 /V 1 /D "%wpipath%\WPI.hta" /f i m using this to run it from a cd but its not working on a desktop what changes should b applied plzzzzzz help me out a little more.thxxx.May God Bless u.
shk86 Posted March 24, 2010 Author Posted March 24, 2010 hats off to u guyz.thanks alot for helping..nice understandable script.many appriciations.
jaclaz Posted March 24, 2010 Posted March 24, 2010 for /f "delims=: tokens=1" %%i in ("%~dp0") do set drive=%%i:set wpipath=%drive%\wpiIf you have it on desktop, it is likely to return something like:C:\Documents and Settings\User\Desktop\\wpiwhich BTW has an additional problem, i.e. contains a space, not a problem in itself but may become one further in the script.Please also understand that BESIDES THE FACT THAT THERE IS NO NEED WHATSOEVER to use a FOR /F loop to get %~dp0, as already said, the result ofSet drive=%~dp0which is the recommended way, as well as the overcomplex one you chose, will be a path with a trailing backslash, which, consequently, will result in something like:drive=C:\whatever\wpipath=C:\whatever\\wpiwhich is invalid.Of course if the batch is in a folder called wpi on desktop, the result of Set drive=%~dp0will be:drive=C:\whatever\wpiandwpipath=C:\whatever\wpi\\wpijaclaz
Yzöwl Posted March 25, 2010 Posted March 25, 2010 o u rock jaclaz i understood it clearly .many regards to u...i have 1 more thing to ask suppose i have a folder on desktop "wpi" containing wpi.hta in it and $oem$ folder beside wpi folder containing runwpi batch file. could the same command will b used for opening the wpi.hta.In order to do that all you need is a batch file containing this:@"%~dp0..\wpi\wpi.hta"
firefox99 Posted March 25, 2010 Posted March 25, 2010 understood sir jacloz..thxx..yzowl realy easy to handle command i dont have to do any thing to it.it workss i wonder if i could use this to execute wpi.hta from cd drive.will it work ??
shk86 Posted March 25, 2010 Author Posted March 25, 2010 hizzz yzowl .can u explain what these 2 dot after dp0 in thiz command represents? @"%~dp0..\wpi\wpi.hta" and plz explain the function of this command.ill b realy grateful.
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now