2

If I type %APPDATA%\Skype into Windows Explorer then Windows Explorer shows me the content of C:\Users\Stevew\AppData\Roaming\Skype.

But if I do this in C#

Directory.GetFiles(@"%APPDATA%\Skype");

then I get an exception saying Could not find a part of the path 'C:\\Users\\Stevew\\Documents\\Visual Studio 2010\\Projects\\TestSkype\\TestResults\\Stevew_PC 2014-05-29 15_45_30\\Out\\%APPDATA%\\Skype'.

I suppose the %APPDATA%-part was not parsed. How can read the content of C:\Users\Stevew\AppData\Roaming\Skype using this syntax?

I know about Environment.SpecialFolder.ApplicationData, but I want to use the %SOMETHING%-syntax in this case, I want to be able to use any of the environment variables. I've tried to search, but I don't really know what to search for.

Petew
  • 150
  • 7
  • %APPDATA% is a windows shell thing. The .NET library won't know this syntax. – abhi May 29 '14 at 14:03
  • 1
    Have a look at [C# getting the path of %AppData%](http://stackoverflow.com/questions/867485/c-sharp-getting-the-path-of-appdata) – huMpty duMpty May 29 '14 at 14:04
  • 1
    @huMptyduMpty The OP posted that he doesn't want to use that syntax. ``Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)`` – abhi May 29 '14 at 14:05
  • @abhi: I didn't answer the question!!! This is a comment, since is lead user to right path, I mean to use `Environment.GetFolderPath` – huMpty duMpty May 29 '14 at 14:06
  • 1
    try this: string AppData = Environment.ExpandEnvironmentVariables("%AppData%"); – Bit May 29 '14 at 14:07

1 Answers1

4

Have a look at Environment.ExpandEnvironmentVariables:

var path = Environment.ExpandEnvironmentVariables(@"%APPDATA%\Skype");

should return the desired value.

Gene
  • 4,192
  • 5
  • 32
  • 56