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):
Code:
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)) {
loadUserData();
// ...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 {
Directory.CreateDirectory(app_dir);
} 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. :)