Finding My Documents

Blitz3D Forums/Blitz3D Programming/Finding My Documents

I’ve searched around a bit and there does seem to be some code floating around to find out what the current location of ‘my documents’ is on XP and Vista but I can’t find a solution to this in Blitz3D. There surely has to be a way if it’s true that Vista won’t let programs write data outside of My Documents in some modes, as others on these forums are claiming, otherwise Blitz3D would be useless for anyone running Vista.

under xp if you access the registry key HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders

see key 'Personal' has the location to 'My Documents'

not sure about vista though.

kev

I don’t really know how to access registry keys, and I’m not sure I really want to start messing about with registry. Even if I did learn that wouldn’t really help me if it’s an XP only solution. Perhaps if enough people lodge their vote we could get Mark to extend the GetEnv$() command.

Maybe you could use the SHGetFolderPathA function from shell32.decls ? Here is the msdn description:
http://msdn2.microsoft.com/en-us/library/ms647764.aspx
;Save these lines as a textfile in the directory c:\program files\blitz3d\userlibs
;and call the file 'shell32.decls'
;-------------------------------------
;.lib "shell32.dll"

;api_GetFolderPath%(hwnd, p1, p2, p3, out*) : "SHGetFolderPathA"
;-------------------------------------
;it will enable the api_getfolderpath command


	Print GetMyDocumentsPath$()
	
	WaitKey()	
	End

;-------------------------------------------------------------------------------------------------------
;											GetMyDocumentsPath()
;-------------------------------------------------------------------------------------------------------
;uses SHGetFolderPathA to get the mydocuments folder
Function GetMyDocumentsPath$()

	bank = CreateBank(256)
	
	api_GetFolderPath(0, $5, 0, 0, bank)
	
	s$ = ""
	For i = 0 To 255
		b = PeekByte(bank, i)
		If b = 0 Then Exit
		s$ = s$ + Chr$(b)
	Next
	
	FreeBank bank
	
	If Right$(s$, 1) <> "" Then s$ = s$ + ""
	
	Return s$
	
End Function	


Thank you so much, that works a treat. Perhaps you should consider adding it to the code archives, I'm sure many people will find that code very useful indeed. Once again, thank you very much!

Okay, will do that. I'm glad it works.