用C#写的一个可以查看和修改文件或目录所有属性的工具SeeFiles,某些情况下,我们会将一些文件设置为系统和隐藏属性,而不想让人看到。为什么不想?你懂得。
【网通】点击这里下载全部源程序 【电信、网通】点击此处下载全部源程序
【下载说明】
1、单击上面这个地址,打开下载页面。
2、点普通下载--等待30秒--点“下载”按钮--保存
主要源程序:
/*
* Created by SharpDevelop.
* User: PJ
* Date: 2012-7-13
* Time: 10:35
*
* To change this template use Tools | Options | Coding | Edit Standard Headers.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Windows.Forms;
using System.IO;
using System.Diagnostics;
namespace SeeFiles
{
/// <summary>
/// Description of MainForm.
/// </summary>
public partial class MainForm : Form
{
private List<FileSystemInfo> file_system_info=null;
public MainForm()
{
//
// The InitializeComponent() call is required for Windows Forms designer support.
//
InitializeComponent();
//
// TODO: Add constructor code after the InitializeComponent() call.
//
}
void RunDosCommand(string cmd)
{
Process p=new Process();
p.StartInfo.FileName="cmd.exe";
p.StartInfo.UseShellExecute=false;
p.StartInfo.RedirectStandardInput=false;
p.StartInfo.Arguments="/c "+cmd;
p.StartInfo.RedirectStandardOutput=true;
p.StartInfo.CreateNoWindow=true;
p.Start();
p.WaitForExit();
p.Close();
}
void BtnBrowserFolderClick(object sender, EventArgs e)
{
FolderBrowserDialog fbd=new FolderBrowserDialog();
fbd.ShowNewFolderButton = false;
fbd.SelectedPath = Environment.CurrentDirectory;
if(fbd.ShowDialog()==DialogResult.OK)
{
tbxFolder.Text=fbd.SelectedPath;
listBox1.Items.Clear();
ListAll(fbd.SelectedPath);
}
}
void ListAll(string path)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
foreach(DirectoryInfo d in dirInfo.GetDirectories())
{
listBox1.Items.Add(d.Name);
}
foreach(FileInfo f in dirInfo.GetFiles())
{
listBox1.Items.Add(f.Name);
}
if(file_system_info==null)
file_system_info=new List<FileSystemInfo>();
else
file_system_info.Clear();
foreach(FileSystemInfo fsi in dirInfo.GetFileSystemInfos())
{
file_system_info.Add(fsi);
}
}
void ListBox1SelectedIndexChanged(object sender, EventArgs e)
{
int select_index = listBox1.SelectedIndex;
FileSystemInfo fsi=this.file_system_info[select_index];
this.chkArchive.Checked = ((fsi.Attributes & FileAttributes.Archive)==FileAttributes.Archive) ? true : false;
this.chkReadOnly.Checked = ((fsi.Attributes & FileAttributes.ReadOnly)==FileAttributes.ReadOnly) ? true : false;
this.chkSystem.Checked = ((fsi.Attributes & FileAttributes.System)==FileAttributes.System) ? true : false;
this.chkHidden.Checked = ((fsi.Attributes & FileAttributes.Hidden)==FileAttributes.Hidden) ? true : false;
this.chkDirectory.Checked = ((fsi.Attributes & FileAttributes.Directory)==FileAttributes.Directory) ? true : false;
this.chkTemporary.Checked = ((fsi.Attributes & FileAttributes.Temporary)==FileAttributes.Temporary) ? true : false;
this.chkOffline.Checked = ((fsi.Attributes & FileAttributes.Offline)==FileAttributes.Offline) ? true : false;
this.chkDevice.Checked = ((fsi.Attributes & FileAttributes.Device)==FileAttributes.Device) ? true : false;
this.chkNormal.Checked = ((fsi.Attributes & FileAttributes.Normal)==FileAttributes.Normal) ? true : false;
this.chkCompressed.Checked = ((fsi.Attributes & FileAttributes.Compressed)==FileAttributes.Compressed) ? true : false;
this.chkSparseFile.Checked = ((fsi.Attributes & FileAttributes.SparseFile)==FileAttributes.SparseFile) ? true : false;
this.chkReparsePoint.Checked = ((fsi.Attributes & FileAttributes.ReparsePoint)==FileAttributes.ReparsePoint) ? true : false;
this.chkEncrypted.Checked = ((fsi.Attributes & FileAttributes.Encrypted)==FileAttributes.Encrypted) ? true : false;
this.chkNotContentIndexed.Checked = ((fsi.Attributes & FileAttributes.NotContentIndexed)==FileAttributes.NotContentIndexed) ? true : false;
}
void ChkSystemMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChangeAttribute(object sender)
{
CheckBox chkbox = (CheckBox)sender;
int select_index = listBox1.SelectedIndex;
FileSystemInfo fsi=this.file_system_info[select_index];
FileAttributes temp;
switch(int.Parse(chkbox.Tag.ToString()))
{
case 1:
temp = FileAttributes.ReadOnly;
break;
case 2:
temp = FileAttributes.Hidden;
break;
case 4:
temp = FileAttributes.System;
break;
case 16:
temp = FileAttributes.Directory;
break;
case 32:
temp = FileAttributes.Archive;
break;
case 64:
temp = FileAttributes.Device;
break;
case 128:
temp = FileAttributes.Normal;
break;
case 256:
temp = FileAttributes.Temporary;
break;
case 512:
temp = FileAttributes.SparseFile;
break;
case 1024:
temp = FileAttributes.ReparsePoint;
break;
case 2048:
temp = FileAttributes.Compressed;
break;
case 4096:
temp = FileAttributes.Offline;
break;
case 8192:
temp = FileAttributes.NotContentIndexed;
break;
case 16384:
temp = FileAttributes.Encrypted;
break;
default:
temp = FileAttributes.Normal;
break;
}
if(chkbox.Checked)
fsi.Attributes = fsi.Attributes | temp;
else
fsi.Attributes = fsi.Attributes & ~temp;
}
void ChkHiddenMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkReadOnlyMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkArchiveMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkDirectoryMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkTemporaryMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkOfflineMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkNormalMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkDeviceMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkCompressedMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkSparseFileMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkReparsePointMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkEncryptedMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void ChkNotContentIndexedMouseClick(object sender, MouseEventArgs e)
{
ChangeAttribute(sender);
}
void BtnOpenClick(object sender, EventArgs e)
{
if( this.listBox1.SelectedItem.ToString() != "" )
{
this.RunDosCommand("start \"\" \""+this.tbxFolder.Text.ToString()+"\\"+this.listBox1.SelectedItem.ToString()+"\"");
}
}
}
}
【更多阅读】