Getting location of My Documents folder
Archives Forums/Win32 Discussion/Getting location of My Documents folder
| ||
Normally I would throw all my game data into the games directory under Program Files, but thanks to Vista and it's UAC I now have to think about storing any files that will be modifled elsewhere. What I'm currently doing is retrieving the shared applications data folder using the getenv_ command. However, I want to fall-back to the user's own My Documents folder if this fails (plus I need it for user designed levels and such like). So, the question is... How do I get the physical location of the My Documents folder? I can't simply use HOMEDRIVE and HOMEPATH, because these point to the folder held under Documents and Settings for the current user, but not the My Documents folder. I can't simply add /My Documents/ on the end as this wouldn't work for those that have moved the location of this folder (like me), plus it's not actually called that in a lot of countries. I've tried Googling, but can't find anything useful at the moment. Any ideas? I'm using BlitzMax. |
| ||
I poked around for a moment, and found the following in the windows registry: HKEY_current_User\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell folders That locations has the links to all the 'special' folders, including 'My Documents'. You can find some code to access the windows registry here: http://www.blitzforum.de/forum/viewtopic.php?t=15521 There's probably also a windows API call that returns the location of these folders, but I have no idea which one of how to use it. :-? |
| ||
deleted. Sorry not relevent |
| ||
There's a Max module called "Volumes" (available here) which has a cross-platform function called GetUserDocumentsDir which may be of use. The module is also available via syncmods (see my sig below for more details) It uses system APIs to get the information, rather than hacking the registry (which is fine if you like that kind of thing). |
| ||
Thanks guys. I'll give them a whirl and see what happens. |
| ||
Brucey -- Just checked out your module. Pretty nice one, definitely saving a copy. |
| ||
I just made a pass through four OSes using Brucey's module (which looks quite handy), checking out GetUserDocumentsDir(). It seems to work fine on XP Pro SP2 and MacOS 10.3.9. However, in Ubuntu 6.06, I found that GetUserDocumentsDir() returned (IIRC) "home/wendellm/Documents" which seems reasonable except that the "Documents" folder doesn't exist. Trying the Windows version in Win 98 SE causes an error about linking to Shell32.dll. So, just a potential heads-up about using it with these two environments. UPDATE: I tried the approach below (based on http://blitzbasic.com/Community/posts.php?topic=45722 ) and it works in 98 SE: |
| ||
Trying the Windows version in Win 98 SE causes an error about linking to Shell32.dll. So, just a potential heads-up about using it with these two environments. This is interesting... I don't have a Window 98 box anymore but I think the problem is that Windows 98 (and 95's) DLL was just called Shell.dll though I may be wrong. If this is the case, I'm not sure how you'd tell the BlitzCompiler to load from Shell.dll on Windows 98 machines and Shell32.dll on Windows XP. :S |
| ||
Seems to work just fine in Vista. One thing to watch out for... I have My Documents pointing to my second hard drive, and not a folder on there, and it adds a second '\' to the path returned, i.e. I got 'C:\\'. (Please don't ask why my second hard drive is C, long story!). |
| ||
If it's the code that I posted above which is having a problem with "My Documents" being the root of C:, perhaps replacing Return Trim(sp$) + "\"with sp = Trim(sp) If sp[sp.length - 1] <> Asc("\") Then sp :+ "\" Return spwill do the trick? |
| ||
there's another problem in there somewhere. when I run it on my PC, I get the following results: C:\Documents and Settings\Administrator\Start Menu\Programs\ C:\Documents and Settings\Administrator\My Documents\ C:\Documents and Settings\Administrator\Desktopettings\Administrator\Start Menu\Programs\ As you can see, the "Desktop" location has an additional (incorrect) 'ettings\Administrator\Start Menu\Programs\' appended to the end of it. Perhaps there's some old data in the bank that's not getting zeroed out? |