G
G. Richard Bellamy
I'm trying to unset the Encrypted attribute on all the files in a path.
The attribute is not getting set. What am I doing wrong?
Perhaps there's another newsgroup I can send this to?
Here's the code:
=============================================
using System;
using System.Diagnostics;
using System.IO;
namespace efsfind
{
/// <summary>
/// Searches a path, looking for EFS attribute.
/// Does not handle trailing spaces in names.
/// </summary>
class ConsoleMain
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ConsoleMain cm = new ConsoleMain();
Arguments commandLine = new Arguments(args);
string path = commandLine["path"];
if (null != path) {
cm.ProcessDirectory (path);
}
}
private void ProcessDirectory(string path)
{
//Console.WriteLine ("{0}", path);
if (null != path && 0 < path.Length)
{
try
{
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileSystemInfo fileSystemInfo in
dir.GetFileSystemInfos ())
{
if (fileSystemInfo is FileInfo)
{
FileInfo file = (FileInfo) fileSystemInfo;
FileAttributes fileAttrib = file.Attributes;
if (FileAttributes.Encrypted ==
(FileAttributes.Encrypted & fileAttrib))
{
Console.Write ("{0}::[{1}", file.FullName,
fileAttrib);
fileAttrib = fileAttrib &
(~FileAttributes.Encrypted);
file.Attributes = fileAttrib;
file.Refresh ();
Console.WriteLine (" ==> {0}]", fileAttrib);
Console.WriteLine ("After update: {0}",
file.Attributes);
}
}
else
{
ProcessDirectory (fileSystemInfo.FullName);
}
}
}
catch (Exception e)
{
Console.WriteLine (e);
}
}
}
}
}
=============================================
The attribute is not getting set. What am I doing wrong?
Perhaps there's another newsgroup I can send this to?
Here's the code:
=============================================
using System;
using System.Diagnostics;
using System.IO;
namespace efsfind
{
/// <summary>
/// Searches a path, looking for EFS attribute.
/// Does not handle trailing spaces in names.
/// </summary>
class ConsoleMain
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
ConsoleMain cm = new ConsoleMain();
Arguments commandLine = new Arguments(args);
string path = commandLine["path"];
if (null != path) {
cm.ProcessDirectory (path);
}
}
private void ProcessDirectory(string path)
{
//Console.WriteLine ("{0}", path);
if (null != path && 0 < path.Length)
{
try
{
DirectoryInfo dir = new DirectoryInfo(path);
foreach (FileSystemInfo fileSystemInfo in
dir.GetFileSystemInfos ())
{
if (fileSystemInfo is FileInfo)
{
FileInfo file = (FileInfo) fileSystemInfo;
FileAttributes fileAttrib = file.Attributes;
if (FileAttributes.Encrypted ==
(FileAttributes.Encrypted & fileAttrib))
{
Console.Write ("{0}::[{1}", file.FullName,
fileAttrib);
fileAttrib = fileAttrib &
(~FileAttributes.Encrypted);
file.Attributes = fileAttrib;
file.Refresh ();
Console.WriteLine (" ==> {0}]", fileAttrib);
Console.WriteLine ("After update: {0}",
file.Attributes);
}
}
else
{
ProcessDirectory (fileSystemInfo.FullName);
}
}
}
catch (Exception e)
{
Console.WriteLine (e);
}
}
}
}
}
=============================================