Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > C# and C > C# 4.0 aka C# 2010 > BOOK: Beginning Visual C# 2010
Password Reminder
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Beginning Visual C# 2010
This is the forum to discuss the Wrox book Beginning Visual C# 2010 by Karli Watson, Christian Nagel, Jacob Hammer Pedersen, Jon D. Reid, Morgan Skinner, ; ISBN: 9780470502266
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning Visual C# 2010 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old July 17th, 2012, 06:58 PM
Authorized User
Points: 54, Level: 1
Points: 54, Level: 1 Points: 54, Level: 1 Points: 54, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
Join Date: Jul 2012
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Default Directory.Exists gives false positives, and Directory.CreateDirectory fails to create

EDIT: Please ignore (or delete) this post. I am, without doubt, an idiot. I was looking in C:\Users\me\Roaming and not in C:\Users\me\AppData\Roaming. And to think they trust me behind a keyboard...

Below is a class I'm working on. The constructor looks to see if a directory exists and if it doesn't it creates it. Well that's the theory anyway.

Here's the code (problem described below):

class UserManager {

        string app_data = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData).ToString();
        string app_dir, config_file;
        string working_dir;

        public UserManager() {

            app_dir = app_data + @"\Foo2";                       // Where we store user data
            config_file = app_dir + @"\userdata.config";        // User configuration file

            // Read the configuration file if it exists...
            if (File.Exists(config_file)) {
            // ...if there is no configuration file then lets create one.
            } else {
                // Most likely the correct directory won't exist, so we make it.
                if  ( ! Directory.Exists(app_dir) ) {
                    try {
                    } catch {
                        MessageBox.Show("Error creating directory, " + app_dir);


        public void loadUserData () {

OK, so I've tried single-stepping through this to find out what's wrong and I found two issues that don't act the way I would expect them to.

First: The if statement, if ( ! Directory.Exists(app_dir) ), shows true, indicating that the directory does not exist, the first time I run it. When I run it a second time it shows false as if the directory now exists however I do not see the directory via Windows Explorer.

If I change the name from "Foo" to "Foo1" then it, again, works the first time and fails from then again. Changing to "Foo2" repeats the cycle, and so on.

Second: when the if statement is true (directory doesn't exist) then the Directory.CreateDirectory(app_dir) executes without error but, once again, no directory is actually created.

As always, thanks for any and all assistance. :)

Last edited by KaneT; July 17th, 2012 at 07:42 PM..

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Check to make sure a directory exists stonesbg ASP.NET 2.0 Basics 3 January 18th, 2007 03:25 PM
How to Create new folder(directory) in Srever ? Raam ASP.NET 2.0 Professional 1 May 10th, 2006 12:48 PM
create xsl file in c directory keyvanjan Classic ASP Basics 2 June 21st, 2005 04:52 PM
check for directory, or create new if not found amerk20 VB How-To 1 April 8th, 2005 12:18 PM
could not create new directory in browserfile.aspx raja_699 BOOK: ASP.NET Website Programming Problem-Design-Solution 2 January 25th, 2005 01:12 PM

All times are GMT -4. The time now is 09:38 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.