Valerie Posted June 30, 2009 Share Posted June 30, 2009 Win XP Home, SP.3 Cmd.exe batch scripting.Can Null (hex 00) be used as a delimiter in a For loop?Thanks. Link to comment Share on other sites More sharing options...
jaclaz Posted June 30, 2009 Share Posted June 30, 2009 Win XP Home, SP.3 Cmd.exe batch scripting.Can Null (hex 00) be used as a delimiter in a For loop?Thanks.NO. (AFAIK)Maybe if you post an example of the FOR loop that you have in mind there could be some workaround. .unsure:jaclaz Link to comment Share on other sites More sharing options...
Valerie Posted July 1, 2009 Author Share Posted July 1, 2009 Thanks Jaclaz. I don't have a script yet as couldn't find info on how to use null as a delimiter.I'm trying to get drive letter assignments into variables using Fsutil as shown:←C:\>fsutil fsinfo drivesDrives: A:\ C:\ D:\ E:\ F:\ G:\←C:\>Seems to me that the delimiter in the above is a space but when tried using a For loop like:│@echo off│cls││setlocal enabledelayedexpansion││For /f "tokens=1-6 delims= " %%A in ('fsutil fsinfo drives') do (│ set one=%%B│ set two=%%C│ set tre=%%D│ set for=%%E│ set fiv=%%F│)│echo One = !one! Two = !two! Three = !tre! Four = !for! Five = !fiv!│only A:\ was returned.So had a look at the Fsutil output in a hex editor with the result:It now seems that the delimiter is null (hex 00) hence my query.Any advice appreciated.V. Link to comment Share on other sites More sharing options...
Scr1ptW1zard Posted July 1, 2009 Share Posted July 1, 2009 I ran into this exact issue! Here is what I came up with to get around this:@echo offsetlocal enabledelayedexpansionfor /f "tokens=*" %%a in ('fsutil fsinfo drives^|more') do ( set drive=%%a set drive=!drive:Drives:=! set drive=!drive: =! echo !drive! fsutil fsinfo volumeinfo !drive!)endlocal Link to comment Share on other sites More sharing options...
jaclaz Posted July 1, 2009 Share Posted July 1, 2009 (edited) A similar solution to the one by Scr1ptW1zard , possibly simpler :@ECHO OFFSETLOCAL ENABLEDELAYEDEXPANSIONFOR /F "tokens=1,2 delims=: " %%A in ('fsutil fsinfo drives^|more') DO (IF NOT %%B.==\. (SET drives=%%B:) ELSE (SET drives=!drives!,%%A:))SET drivesENDLOCAL jaclaz Edited July 1, 2009 by jaclaz Link to comment Share on other sites More sharing options...
Valerie Posted July 1, 2009 Author Share Posted July 1, 2009 Thank you both, lots there for me to ponder. Link to comment Share on other sites More sharing options...
jaclaz Posted July 1, 2009 Share Posted July 1, 2009 Thank you both, lots there for me to ponder.Another way to ponder:@ECHO OFFSET drives=SET separator=FOR /F "tokens=1,2 delims=\ " %%A in ('fsutil fsinfo drives^|more') DO CALL :SET_var %%A %%BSET drivesGOTO :EOF:SET_varSET separator=,IF NOT %2.==. SHIFT&SET separator=Set drives=%drives%%separator%%1GOTO :EOF(doesn't need Delayed Expansion enabled) jaclaz Link to comment Share on other sites More sharing options...
Yzöwl Posted July 1, 2009 Share Posted July 1, 2009 Of course it depends upon what you specifically need to do with each outputted result!Here is an example without knowing the number of drives@Echo off&Setlocal enableextensionsFor /f "tokens=1* delims= " %%# In ('Fsutil Fsinfo Drives') Do Call :_ %%$Goto :Eof:_If %1' Neq ' ( Echo/Set "drv=%1" Shift)&&Goto _You would just change Line 6 to suit the task you need to perform on each result. Link to comment Share on other sites More sharing options...
Bilou_Gateux Posted July 1, 2009 Share Posted July 1, 2009 (edited) I have used in the past part of script written by Yzöwl with a nice workaround if we don't have the more command somewhere in our path.'Fsutil Fsinfo Drives^|More''Fsutil Fsinfo Drives^|find /v ""'Jaclaz script output all drives letters with comma as separator.Yzöwl script output only the first found drive letter?could you explain why you use Call :_ %%$ instead of Call :_ %%#I would like to learn something i currently don't understand. Edited July 1, 2009 by Bilou_Gateux Link to comment Share on other sites More sharing options...
Yzöwl Posted July 1, 2009 Share Posted July 1, 2009 My apologies, the example I provided was written and tested only on Vista!@Echo off&Setlocal enableextensionsFor /f "delims=" %%# In ('Fsutil Fsinfo Drives^|More') Do Call :_ %%#Goto :Eof:_If %1' Neq ' (Echo/%1|Find "\">Nul&&( Echo/Set "drv=%1" )&Shift)&&Goto _like the previous example change line 6 to suit the task you need to perform on each result.@Bilouin answer to your question, I used %%$ and %%# in the same way as you would use %%b and %%a respectively.b, (second token), comes after a, (first token)$, (second token), comes after #, (first token)In that specific case Drives: was an unwanted first token Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now