Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I want to get the foldername of the profiles on a pc in a variable to check if there exist a specific folder.
The problem is I get spaces at the beginning and the end of the var like:
" c:\winnt\profiles\all users "
" c:\winnt\profiles\uli "
...
That means I can't work with it.
Deleting all spaces is not possible cause of the all users folder.
Here is my not really working code:
@echo off
cls
FOR /d %%A in (c:\winnt\Profiles\*) do call :sub1 %%A
goto :eof
:sub1
set PROFIL=%*
echo "%PROFIL%"
:eof
thanks in advance for any help
uli

Hi uli,
not sure why you get spaces. My structure is different, but this works:
@echo off
for /f "tokens=* delims=" %%A in ('dir /s/b/ad "\Documents and Settings\all*"') do (
echo %%A
)
=====================================
If at first you don't succeed, you're about average.M2

Thanks for your quick help M2,
your solution works perfect as long as I don't call a procedur.
Then it is nearly the same effect." foldername"
Seems to be a Bug in NT4.
I want it in a procedur cause I delete a folder in every profile and want to analyze an errorcode for a logfile.uli

Hi uli,
Post your code.
=====================================
If at first you don't succeed, you're about average.M2

M2, you pointed me in the right direction: :-)
This seems to be the solution:for /f "tokens=* delims=" %%A in ('dir /s/b/ad "c:\winnt\Profiles\.folder"') do call :sub1 %%A
goto :eof
:sub1set folder=%*
set folder=%folder:~1%
rd /s /q "%folder%"
if "%errorlevel%" == "0" (echo %folder% erased >>log.txt)

Hi uli,
Yeah, we're left wondering if it's an NT4 bug.
NOTES:
When testing for errorlevel you can skip the == and simply use:
if errorlevel X do
More important, in your case, note that an errorlevel test will resolve TRUE if the errorlevel is EQUAL OR MORE. So a test for errorlevel 0 will always be true.
What you probably want here is:
if not errorlevel 1 echo it worked
=====================================
If at first you don't succeed, you're about average.M2

Hi M2,
thanks for the errorlevel advice. Helped to avoid one of these little "uli" bugs in my script. I am a bit in a hurry cause of this project. (The profile thing is just a little part...)
uli

![]() |
batch programming questio...
|
Searching file w/ C++
|

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