joe_pool_is
Well-known member
Im to a place where I need to modify a files attributes so that I can encrypt or decrypt the file because Hidden or ReadOnly files fail.
Ive written a basic static method (so my threads can call it), and I wanted to post it here for criticism or suggestions:
Ive written a basic static method (so my threads can call it), and I wanted to post it here for criticism or suggestions:
C#:
static bool FileExists(string file) {
if (File.Exists(file) == true) {
FileInfo fi = new FileInfo(file);
if ((fi.Attributes & FileAttributes.Directory) == FileAttributes.Directory) {
return false;
}
if ((fi.Attributes & FileAttributes.ReadOnly) == FileAttributes.ReadOnly) {
fi.Attributes &= FileAttributes.ReadOnly; // & removes, | adds
// or, toggle the ReadOnly portion only (use one or the other, but not both)
// fi.Attributes ^= FileAttributes.ReadOnly;
}
if ((fi.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden){
fi.Attributes &= FileAttributes.Hidden;
}
return true;
} else {
return false;
}
}