What is the best way to find a user's Documents folder on XP and Vista from a batch script? Is it safe to assume that it's %USERPROFILE%\Documents?
|
A complete reference of environment variables can be found here, on the microsoft site, it can also be found in a registry key.
In the event the My Documents folder is not in the standard location, pulling the information out the registry key is probably the most reliable way. |
|||||
|
|
so my final version looks like this:
where the character between delims= and the following " is a single tab. Make sure your editor emits a tab and not spaces. EDIT: On Windows 7 (and maybe all windows) you shouldn't specify delims= at all as it defaults to which is the whitespace used inbetween the tokens and not just a tab. |
||||
|
|
|
That'll be the place that the system knows about (although it's My Documents in XP), however you'll have to judge for yourself whether or not that's a safe assumption for your environment. If you use My Documents redirection, though, that variable should be set to whatever you redirect to with the default set to c:\documents and settings[username] in XP or c:\users[username] in Vista. |
|||
|
In Vista it's %UserProfile%\Documents, but in WinXP it's %UserProfile%\My Documents. That's the only difference between the 2 different OS's. And don't forget that the Videos, Music, and Photos are under C:\Users[username] in Vista too. -JFV |
|||
|
|
|
Windows XP names it 'My Documents' and Vista names it 'Documents'. You might put in a script to determine which OS you are running.
|
||||
|
|
|
It's only "My Documents" etc on english windows. If you're using another language the pathname is "translated" (except on Vista) |
|||
|
|
|
:getuserdoc folder from registry set idkey="HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" call:fetchvalue errorlevelvariable %idkey% Personal goto:eof errorlevel is set if fail :fetchvalue set /a %1=0 REG query %2 /v %3 if ERRORLEVEL 1 (set /a %1=1&goto :eof) FOR /F "tokens=3* skip=2 delims= " %%A IN ('REG QUERY %2 /v %3') DO SET %3="%%A" goto:eof EDIT Use Button GETSource as this wenpage cant display answer characters are removed! |
||||
|