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

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

【更多阅读】

  1. [译]在C# .NET2.0实现单实例应用程序
  2. [原]IniFile.cs:C#来操作ini配置文件
  3. [原]使用Excel的VBA来读取和修改bmp位图像素数据
  4. [译]C#控制计算机的并口LPT
  5. [原]PjCleanSystemTrash:C#清除系统盘垃圾
  6. [译]C#控制计算机的并口LPT
  7. [原]WMICodeCreator:C#产生WMI代码的工具
  8. [原]PjConvertImageFormat:用FreeImage.NET写的一个35种图像格式转换程序
  9. [原]ManageStartUpApps:C#操作注册表来读取和修改开机启动项
  10. [译]在C# .NET2.0实现单实例应用程序

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值