Re: Hello and beginner help
For future reference, please provide meaningful thread titles that describe the topic of the thread. Otherwise we have to open every single thread to find those that might be relevant to us, which can be a big time waster and may turn people off viewing your thread.
As for the question, you generally cannot just include an environment variable in a literal string an expect it to be interpreted correctly. What you can do is call Environment.ExpandEnvironmentVariables and pass your string to it, then use the result of that, which will contain the resolved values of the environment variables:
Code:
My.Computer.FileSystem.CopyDirectory(Environment.ExpandEnvironmentVariables("C:\Documents and Settings\%username%\My Documents"), "U:\Backup", True)
In this case though, that's a very bad idea. There are various reasons that that path could be incorrect:
1. The user is not using Windows XP, i.e. Vista and Win 7 use a different default path.
2. The user has installed Windows on other than C: drive.
3. The user has moved their document store to a different location, e.g. I always move mine to a secondary hard drive so that it will be unaffected if I ever have to reformat the system drive and reinstall Windows.
You should always use standard methods for getting standard folder paths, which means either Environment.GetFolderPath or My.Computer.FileSystem.SpecialDirectories. That will give you the correct path for folders like user documents no matter where they are because it queries Windows itself.