I am trying to list the files inside the directory %TEMP% and %USERNAME% in a text box so people can see what files exist there. When I type C:\users\%username%… It fails to work.
Here is my code:
string strDirLocal = @"C:\users\USERPROFILE\desktop";
if (System.IO.Directory.Exists(strDirLocal))
{
foreach (string sPath in System.IO.Directory.GetFiles(strDirLocal, "*.*"))
{
textBox1.Text = textBox1.Text + sPath.Replace(strDirLocal + @"\", "") + "\r\n";
Thank you for taking the time to read this.
What you need to do is expand the
%TEMP%and%USERPROFILE%environment variables in your program and use the result instead of the variable