Question:
How to type a file path on another computer in Visual Basic?
Mason
2013-02-03 12:45:09 UTC
Please help, I need to create a file path like C:\Users\My name\AppData\Roaming\ etc. etc.

But when i run it on another computer is says the file is not found, and that is because in the code i have MY Computer File, not theirs. so how do you make the "C:\Users\"... but after "users", it can access any file on there? Do you have to put %user% in there like "C:\Users\%user%"? Or something else? If you could help that would be awesome!

thanks!
Three answers:
Gardner
2013-02-03 14:42:44 UTC
This link http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.specialdirectories_members%28VS.80%29.aspx will provide you with everything you need to know about accessing special folders via your program.



This link http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.specialdirectories.currentuserapplicationdata%28v=vs.80%29.aspx deals specifically with the application data folder for the current user.
Effie
2013-02-03 12:55:44 UTC
You need to allow that c:\users will be share. Right click on it, and select sharing, give it a name ending by $ sign

Then, you will able to access this folder
?
2013-02-03 13:07:25 UTC
The old school way is to go trough REG query end strip unnecessary parts:



@echo off

for /f "tokens=2*" %%A in ('REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v Desktop') DO (

for %%F in (%%B) do (

set Path=%%F

goto :break

)

)

:break



cd %Path%

echo %Path%

pause



*** You can also use > REG QUERY "HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders" /v AppData to go directly to folder you specified in question.

-----

It will Find the path to Desktop in User account. strip the Desktop if needed or use CD .. and you are good ... It is independent on share setttings


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...