سلام عليكم....
انا عملت هذا الكود
ولكنه ليس عملي
ويأخذ وقت طويل
لو يستطيع احد
ان يعدل في ويخبرني
وشكرا
// created on 3/20/2004 at 1:13 AM
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Threading;
using System.IO;
namespace MyForm {
public class CreatedForm : System.Windows.Forms.Form
{
private System.Windows.Forms.TextBox txtResult;
private System.Windows.Forms.Button btnGenerateLog;
private System.Windows.Forms.CheckBox chkFile;
private System.Windows.Forms.Label label;
private System.Windows.Forms.Label memo;
private System.Windows.Forms.CheckBox chkSize;
private System.Windows.Forms.TextBox txtFiles;
private System.Windows.Forms.TextBox txtPath;
private System.Windows.Forms.CheckBox chkSubFolders;
private int upperY, lowerY, memoX, memoY;
private Thread myTh;
public CreatedForm()
{
InitializeComponent();
memoX = upperY = memo.Location.X;
lowerY = this.Bounds.Right-200;
memoY = memo.Location.Y;
myTh = new Thread(new ThreadStart(MoveLabel));
myTh.Start();
}
// THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
// DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
void InitializeComponent() {
this.chkSubFolders = new System.Windows.Forms.CheckBox();
this.txtPath = new System.Windows.Forms.TextBox();
this.txtFiles = new System.Windows.Forms.TextBox();
this.chkSize = new System.Windows.Forms.CheckBox();
this.memo = new System.Windows.Forms.Label();
this.label = new System.Windows.Forms.Label();
this.chkFile = new System.Windows.Forms.CheckBox();
this.btnGenerateLog = new System.Windows.Forms.Button();
this.txtResult = new System.Windows.Forms.TextBox();
this.SuspendLayout();
//
// chkSubFolders
//
this.chkSubFolders.Location = new System.Drawing.Point(16, 80);
this.chkSubFolders.Name = "chkSubFolders";
this.chkSubFolders.TabIndex = 1;
this.chkSubFolders.Text = "Sub Folders";
//
// txtPath
//
this.txtPath.Location = new System.Drawing.Point(16, 48);
this.txtPath.Name = "txtPath";
this.txtPath.Size = new System.Drawing.Size(464, 21);
this.txtPath.TabIndex = 0;
this.txtPath.Text = "";
this.txtPath.KeyPress += new System.Windows.Forms.KeyPressEventHandler(this.EnablingCnenerateBtn);
//
// txtFiles
//
this.txtFiles.Enabled = false;
this.txtFiles.Location = new System.Drawing.Point(368, 80);
this.txtFiles.Name = "txtFiles";
this.txtFiles.Size = new System.Drawing.Size(112, 21);
this.txtFiles.TabIndex = 4;
this.txtFiles.Text = ".mp3";
//
// chkSize
//
this.chkSize.Location = new System.Drawing.Point(128, 80);
this.chkSize.Name = "chkSize";
this.chkSize.TabIndex = 2;
this.chkSize.Text = "Size";
//
// memo
//
this.memo.Font = new System.Drawing.Font("Comic Sans MS", 9.75F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
this.memo.Location = new System.Drawing.Point(16, 368);
this.memo.Name = "memo";
this.memo.Size = new System.Drawing.Size(240, 64);
this.memo.TabIndex = 8;
this.memo.Text = "Thank You for Using My Prog To contact or comments ==Wael==> MeMoNoNo@YaHoO.CoM";
//
// label
//
this.label.Location = new System.Drawing.Point(16, 16);
this.label.Name = "label";
this.label.Size = new System.Drawing.Size(160, 23);
this.label.TabIndex = 3;
this.label.Text = "Please Enter Your Path:";
//
// chkFile
//
this.chkFile.Location = new System.Drawing.Point(256, 80);
this.chkFile.Name = "chkFile";
this.chkFile.TabIndex = 3;
this.chkFile.Text = "Special Files";
this.chkFile.CheckedChanged += new System.EventHandler(this.ChkFileCheckedChanged);
//
// btnGenerateLog
//
this.btnGenerateLog.Location = new System.Drawing.Point(384, 16);
this.btnGenerateLog.Name = "btnGenerateLog";
this.btnGenerateLog.Size = new System.Drawing.Size(96, 23);
this.btnGenerateLog.TabIndex = 5;
this.btnGenerateLog.Text = "Generate Log";
this.btnGenerateLog.Click += new System.EventHandler(this.BtnGenerateLogClick);
//
// txtResult
//
this.txtResult.Location = new System.Drawing.Point(16, 112);
this.txtResult.Multiline = true;
this.txtResult.Name = "txtResult";
this.txtResult.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.txtResult.Size = new System.Drawing.Size(464, 240);
this.txtResult.TabIndex = 6;
this.txtResult.Text = "";
//
// CreatedForm
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 14);
this.ClientSize = new System.Drawing.Size(504, 446);
this.Controls.Add(this.memo);
this.Controls.Add(this.txtFiles);
this.Controls.Add(this.chkFile);
this.Controls.Add(this.chkSize);
this.Controls.Add(this.chkSubFolders);
this.Controls.Add(this.label);
this.Controls.Add(this.txtPath);
this.Controls.Add(this.btnGenerateLog);
this.Controls.Add(this.txtResult);
this.Name = "CreatedForm";
this.Text = "Log Files Maker";
this.ResumeLayout(false);
}
public static void Main(){
Application.Run(new CreatedForm() );
}
void BtnGenerateLogClick(object sender, System.EventArgs e)
{
try{
DirectoryInfo dir = new DirectoryInfo(txtPath.Text);
txtResult.Text = "";
if(chkSubFolders.Checked){
getSubFolders(dir);
}//sub folfers
else{
getFolders(dir);
getFiles(dir);
}//not sub folders
}
catch(Exception ex){txtResult.Text = ex.Message;}
}
public void getSubFolders(DirectoryInfo s){
DirectoryInfo[] arr = getFolders(s);
getFiles(s);
if( arr.Length == 0 ){
getFiles(s);
return;
}
for(int j =0; j < arr.Length; j++){
getSubFolders(arr[j]);
}
}
//get all folders in a path
public DirectoryInfo[] getFolders(DirectoryInfo dir){
DirectoryInfo[] objs = dir.GetDirectories();
txtResult.Text += "Folders in "+dir.Name+": \r\n";
for(int j =0; j < objs.Length; j++){
txtResult.Text +="\t"+ ((DirectoryInfo)objs[j]).Name + "\r\n";
}
//txtResult.Text = ""+objs.Length;
return objs;
}
public void getFiles(DirectoryInfo obs){
FileInfo[] s = obs.GetFiles();
txtResult.Text += "Files in "+obs.Name+": \r\n";
//printing files of this folder
for(int i =0; i < s.Length ; i++){
if( chkFile.Checked && ((s.Name).Substring( (s.Name).LastIndexOf(".") )).Equals(txtFiles.Text) )
{
txtResult.Text += "\t"+ s.Name;
if( chkSize.Checked )
txtResult.Text += "\tSize : " +s.Length;
txtResult.Text +="\r\n";
}
if( !chkFile.Checked )
{
txtResult.Text += "\t"+ s.Name;
if( chkSize.Checked )
txtResult.Text += "\tSize : " +s.Length;
txtResult.Text +="\r\n";
}
}
//return s;
}
//**********************************************
public void MoveLabel() {
for (int i =0; i<3; i++) {
while (memoX <= lowerY) {
memoX += 10;
memo.Location = new Point(memoX, memoY);
Refresh();
Thread.Sleep(100);
}
while (memoX >=upperY) {
memoX -= 10;
memo.Location = new Point(memoX, memoY);
Refresh();
Thread.Sleep(100);
}
}
}
//***************************************************
void ChkFileCheckedChanged(object sender, System.EventArgs e)
{
if(chkFile.Checked ){
txtFiles.Enabled = true;
}
else{
txtFiles.Enabled = false;
}
}
void EnablingCnenerateBtn(object sender, System.Windows.Forms.KeyPressEventArgs e)
{
System.EventArgs fe = new System.EventArgs();
// txtResult.Text = ""+fe;
if(e.KeyChar=='\r'){
BtnGenerateLogClick(sender , fe);
}
}
}
}