C:\documents and settings

W

Walter Schulz

How to get this directory by some generic statement from .BAT file?

I think you should rephrase your sentence

Or do you mean something like

dir "%allusersprofile%"\..

Ciao, Walter
 
T

Torgeir Bakken (MVP)

Ondrej said:
How to get this directory by some generic statement from .BAT file?

Hi

FOR /F "Tokens=1-2 delims=\" %%i in ("%ALLUSERSPROFILE%") DO SET var1=%%i\%%j
echo %var1%
 
O

Ondrej Sevecek

Nice. Is there some documentation for this trick? Eg. from Microsoft, one
complex and exhaustive?

Ondra.
 
M

Matthias Tacke

Nice. Is there some documentation for this trick? Eg. from Microsoft, one
complex and exhaustive?
Best print out the releevant parts of help and/or
for /?
set /?

and carefully read _every_ sentence. Jerold and some others do magic
with commands every one should know. If you study it, you will have
your heureka ;-)
 
T

Tom Lavedas

This is well documented in the help for SET. All Mr.
Schulman did was recognize there was a subfolder under
the 'Documents and Settings' folder that was always named
the same, that is the 'All Users' folder, and then he
merely parsed that name off of the end of the
AllUsersProfile variable's contents. It's a neat trick,
but fully documented in the /? help text in the sense of
the primatives used.

One approach that is not as well documented might be the
use of the double dot to address the paret directory. I'm
sure it is documented, but I can't point to the exact
place.

This trick is useful for creating a pathspec that works
the same as the one Mr. Schulman's approach provides, but
that doesn't require any parsing. It also does not need
to know anything about the current content of the input
pathspec. So, you can get the pathspec for a file of any
arbitrary name by adding the '\..' string and find its
parent folder by adding a pair of shash double dots
(i.e. '\..\..')

For example, ...

pushd "%ALLUSERSPROFILE%\.."
pushd "%USERSPROFILE%\.."
pushd "C:\Documents and Settings\someuser\My
Documents\somefile\..\..\.."

Watch the wordwrap on that last example.

These all takes you to the same location, but do not
require the environment variable. It's not as pretty, if
it's intended for display purposes. In such cases, use
the parsing technique.

Tom Lavedas
===========
 
M

Matthias Tacke

:
For example, ...

pushd "%ALLUSERSPROFILE%\.."
pushd "%USERSPROFILE%\.."
These all takes you to the same location, but do not
require the environment variable. It's not as pretty, if
it's intended for display purposes. In such cases, use
the parsing technique.

But has the functionality this way:

@echo off
pushd %ALLUSERSPROFILE%\..
set docset=%cd%
popd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top