1.

Solve : relative path my documents?

Answer»

Hello everyone,

FIRST of all, this is my first post here, if this topic isn't in the correct place, simply TELL me (or @mods: move it please)

The title may be misleading. I know there isn't a variable to "My documents".
That's why I need a way around it. Some of us know that the location of "My documents" is stored into the register:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
more specific into the value "Personal"

Well using this I exported the key above (*\Shell Folders) into a .txt which works like a charm.
REG EXPORT "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" "test.txt"

The problem is that is shows all the values in "Shell Folders"
I only need the text after "Personal"= *Path I need*
then I could set in to a variable %MYDOCPATH% or something and I could use that into the bat I'm making to copy stuff into "My Documents"

Could ANYONE help me isolate the path (in a bat file) I need and find a way to set it as a variable.
Thanks in advance,
Kind regards,

Bennieboj

ps: I using WinXP home edition atm but the registry key is the same on every Windows PC (2000, XP, Vista and Win7)Don't bother using REQ EXPORT and a text file. For one thing, you need the batch to be on a writeable volume, and also you'd be creating filesystem clutter. Better to use REQ QUERY and parse the output with FOR /F

Code: [Select]@echo off
for /f "tokens=1-2*" %%A in (' REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" ') do if "%%A"=="Personal" set MYDOCPATH=%%C
echo This user's document folder is: %MYDOCPATH%

As you can SEE, my name is Mike.

Windows 7

Code: [Select]This user's document folder is: C:\Users\Mike\Documents
Windows XP

Code: [Select]This user's document folder is: C:\Documents and Settings\Mike\My Documents
Thanks, this is exactly what I'm looking for. I don't completely understand the code you used, but it works
I had already found that kind of code but it just din't WORK for me.
Once again, thanks a lot for the answer and the fast reply No need to quote the answer just to say thanks, but glad it worked for you.



Discussion

No Comment Found