Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
Well... my forehead is now a bloody pulp...
Try this batch file:
@echo off
set myvar=%ALLUSERSPROFILE%echo String to parse:[%myvar%]
echo.
for /f "usebackq tokens=1-7* delims=\" %%a in (`echo %myvar%`) do call :prtpath %%a %%b %%c %%d %%e %%f %%g
goto EOF:prtpath
echo Element 1 = %1
echo Element 2 = %2
echo Element 3 = %3
echo Element 4 = %4
echo Element 5 = %5
echo Element 6 = %6
echo Element 7 = %7:EOF
---------------------
Here are the results:
String to parse:[C:\Documents and Settings\All Users]Element 1 = C:
Element 2 = Documents
Element 3 = and
Element 4 = Settings
Element 5 = All
Element 6 = Users
Element 7 =Notice that "...delims=\" and there is NO SPACE included there for a delimiter, however, it is tokenizing on \ as well as SPACE!!!!
Is there a way around this behaviour?
Thanks in advance!

duh....
the call to the :prtpath is the problem!
call gets expanded to:
:prtpath C: Documents and Settings All Userswhich is correctly mapped to:
%1 = C:
%2 = Documents
%3 = and
%4 = Settings
%5 = All
%6 = UsersThe trick is to double quote the strings that may contain spaces:
for /f "usebackq tokens=1-7* delims=\" %%a in (`echo %myvar%`) do call :prtpath "%%a" "%%b" "%%c" "%%d" "%%e" "%%f" "%%g"oh well... maybe someone else will learn from my "pulpy" forehead!!!

Jrell... I have actually been searching high and low for topics regarding this issue and also have been beating my head against a wall. I am attempting something very similar. Although what you discuss above adds insight, the result of your double quotes is that you not only get the folder with spaces as a single token, but that passed variable actually contains those same double quotes. Here is what I found when using your modified code:
String to parse:[C:\Documents and Settings\All Users]
Element 1 = "C:"
Element 2 = "Documents and Settings"
Element 3 = "All Users"
Element 4 = ""
Element 5 = ""
Element 6 = ""
Element 7 = ""The quotes make it hard to reuse those values. My code is below:
@echo off
cls
setLocal EnableDelayedExpansiondir /ad /b > dirlist.txt
call :readdirlist
goto eof:readdirlist
REM FOR /F "tokens=1* delims=" %%G IN (dirlist.txt) DO (call :s_size %%G %%H)
REM FOR /F "tokens=1* delims= " %%G IN (dirlist.txt) DO (call :s_size %%G)
REM FOR /F "tokens=* delims=?" %%G IN (dirlist.txt) DO (call :s_size %%G)
FOR /F "tokens=* delims=" %%G IN (dirlist.txt) DO (call :s_size "%%G")
goto eof:s_size
set folder=%1
echo %folder%
goto eof:eof
I am attemting something similar, but cant for instance read from the file, 'Documents and Settings' as one token. After finding your post, I now can get one token but it has quotes on it. Did you come up with any additional findings during your quest that may help me?

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |