|
Post by psycho on Apr 1, 2019 15:25:04 GMT -5
Hello,
I am trying to find out what the path would be for any user (generic) to a desktop file in Windows 10.
The program I have been using for years is written specifically for my computer and username as shown below:
filePath$="C:\Users\myName\Desktop\Schedule Files\"
What do I use in place of "myName" for the program to work for any user on any pc?
Thanks in advance for any help.
John
|
|
|
Post by Chris Iverson on Apr 1, 2019 15:59:23 GMT -5
There's no wildcard to use for that, but we CAN ask Windows to give us the path we want.
The desktop, for example:
CSIDL.DESKTOPDIRECTORY = 16 print GetSpecialFolder$(CSIDL.DESKTOPDIRECTORY) end
Function GetSpecialFolder$(CSIDL) var$ = space$(_MAX_PATH)
CallDLL #shell32, "SHGetFolderPathA",_ 0 as ulong,_ 'HWND, value is reserved CSIDL as long,_ 'CSIDL_ value 0 as ulong,_ 'hToken, blank for 'check current token' 0 as ulong,_ 'dwFlags, 0 for 'get current path'(SHGFP_TYPE_CURRENT) var$ as ptr,_ ret as long
GetSpecialFolder$ = trim$(var$) End Function
|
|
cundo
Full Member
Muchas Gracias!!
Posts: 146
|
Post by cundo on Apr 1, 2019 17:14:39 GMT -5
|
|
|
Post by Chris Iverson on Apr 1, 2019 18:03:19 GMT -5
Well, yes and no.
The File APIs(and therefore, LB's file manipulation commands) do not expand environment variables. You can't just do an open "%APPDATA%\myfile.txt" and get a working file.
You CAN use the Windows API to retrieve the value of the environment variable, and then use that. But then, you're just using a roundabout method of calling SHGetFolderPath().
|
|
|
Post by psycho on Apr 2, 2019 7:14:29 GMT -5
There's no wildcard to use for that, but we CAN ask Windows to give us the path we want. The desktop, for example: CSIDL.DESKTOPDIRECTORY = 16 print GetSpecialFolder$(CSIDL.DESKTOPDIRECTORY) end
Function GetSpecialFolder$(CSIDL) var$ = space$(_MAX_PATH)
CallDLL #shell32, "SHGetFolderPathA",_ 0 as ulong,_ 'HWND, value is reserved CSIDL as long,_ 'CSIDL_ value 0 as ulong,_ 'hToken, blank for 'check current token' 0 as ulong,_ 'dwFlags, 0 for 'get current path'(SHGFP_TYPE_CURRENT) var$ as ptr,_ ret as long
GetSpecialFolder$ = trim$(var$) End Function Perfect!! Thank you Chris! John
|
|
|
Post by metro on Apr 2, 2019 8:25:37 GMT -5
Interesting thanks Chris................ I've learnt something today
for a= 1 to 100 print GetSpecialFolder$(a) next wait end
Function GetSpecialFolder$(CSIDL) var$ = space$(_MAX_PATH)
CallDLL #shell32, "SHGetFolderPathA",_ 0 as ulong,_ 'HWND, value is reserved CSIDL as long,_ 'CSIDL_ value 0 as ulong,_ 'hToken, blank for 'check current token' 0 as ulong,_ 'dwFlags, 0 for 'get current path'(SHGFP_TYPE_CURRENT) var$ as ptr,_ ret as long
GetSpecialFolder$ = trim$(var$) End Function
|
|
|
Post by Chris Iverson on Apr 2, 2019 8:38:09 GMT -5
|
|