Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Directory.Exists returns true when directory is not present

Tags:

c#

.net

windows-7

I am working on an application for Windows 7, and run some routine directory creation code:

string dirPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), "MyDir");    
if (!Directory.Exists(dirPath))
   Directory.CreateDirectory(dirPath);

The problem is that the Directory.Exists line returns true, when I can't see the directory through command line and Windows Explorer. This isn't an issue when working with Windows XP. Is there something going on with Windows 7 that I'm not aware of?

EDIT: Added Path.Combine

like image 232
Blake Blackwell Avatar asked Nov 12 '09 17:11

Blake Blackwell


1 Answers

Please understand that Windows Vista and Windows 7 use virtualization to protect such folders, so you need to check if myDir is in virtualstore,

C:\Users(user name)\AppData\Local\VirtualStore\ProgramData

like image 145
Lex Li Avatar answered Sep 21 '22 02:09

Lex Li