您的位置:首页 > 编程语言 > C#

SeeFiles:C#查看和修改文件或目录所有属性的工具

2012-09-25 16:17 447 查看
用C#写的一个可以查看和修改文件或目录所有属性的工具SeeFiles,某些情况下,我们会将一些文件设置为系统和隐藏属性,而不想让人看到。为什么不想?你懂得。

【网通】点击这里下载全部源程序 [b]【电信、网通】点击此处下载全部源程序[/b]

【下载说明】

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()+"\"");
}
}
}
}

【更多阅读】

[译]在C# .NET2.0实现单实例应用程序
[原]IniFile.cs:C#来操作ini配置文件
[原]使用Excel的VBA来读取和修改bmp位图像素数据
[译]C#控制计算机的并口LPT
[原]PjCleanSystemTrash:C#清除系统盘垃圾
[译]C#控制计算机的并口LPT
[原]WMICodeCreator:C#产生WMI代码的工具
[原]PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序
[原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
[译]在C# .NET2.0实现单实例应用程序
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐