shahryari
جمعه 09 تیر 1391, 14:59 عصر
با سلام
حتما تا حلا پيش اومده كه دنبال يك فايل در سيستم بگردين كه يادتون رفته كجا ذخيره اش كردين؟
در اين مواقع زياد خودنون رو ناراحت نكنين ، اين تاپيك رو بخونين و زود دست بكار بشين:لبخندساده:
در اين تاپيك قصد دارم نحوه ساخت و كد نويسي يك برنامه مفيد رو كه كارش پيدا كردن يك فايل در سيستم هستش ، براتون آموزش بدم
البته با امكانات ويندوز هم ميشه اين كار رو انجام داد منتها ساخت اين برنامه خالي از لطف نيست:بامزه:
**********************
كنترل هاي مورد نياز
------------------------
Button1 جهت شروع جستجو
خصوصيات : پيش فرض
------------------------
Button2 جهت اجراي فايل پيدا شده درصورت نياز
خصوصيات : Enabled= False
------------------------
Label1 جهت نمايش مسير فايل
خصوصيات : text=""
-------------------------
Label2 جهت نمايش پيام سيستم به كاربر
خوصوصيات: با رنگ متفاوت (قرمز) و فونت درشت و text = ""
-------------------------
ComboBox1 جهت نمايش درايو هاي موجود در سيستم
خصوصيات : DropDownStyle = DropDownList
------------------------
ProgerssBar1 جهت نمايش فرايند جستجو
خصوصيات : Visible= False , Style=Marquee
-------------------------
TextBox1 جهت گرفتن نام و پسوند فايل مورد نظر
خصوصيات : پيش فرض
--------------------------
يك فرم به ابعاد 400*300 يا .....
********************************
كد هاي مربوط به فرم لود جهت ليست كردن درايو هاي موجود كه البته يك Function هم دارد :
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sDrive As String, sDrives() As String
sDrives = ListAllDrives()
For Each sDrive In sDrives
Debug.WriteLine(sDrive)
Next
Me.ComboBox1.Items.AddRange(ListAllDrives())
Me.ComboBox1.SelectedIndex = 1
End Sub
Public Function ListAllDrives() As String()
Dim arDrives() As String
arDrives = Directory.GetLogicalDrives()
Return arDrives
End Function
ايندكس كمبو باكس رو بخاطر اين 1 گرفتم كه در ليست درايو ها اولين درايو A و دومين C هست كه هنگام لود شدن بهتره درايو C پيش فرض باشه
------------------------------------------------
كد اصلي جستجو در قالب يك Sub كه بعدا قراره توسط Button1 فراخواني بشه:
Dim Trouver As String
Dim Cherche As String
Sub LireRep(ByVal Chem As String)
Dim Rep, sRp, Obj, sRep, sR2
Dim sCle As String
Dim NbsR As Integer, S As String
Chem = Chem & IIf(Microsoft.VisualBasic.Right(Chem, 1) = "\", "", "\")
Trouver = Dir(Chem & Cherche)
If Trouver <> "" Then Trouver = Chem & Trouver : Exit Sub
'--------------------------------------
Obj = CreateObject("Scripting.FileSystemObject")
Rep = Obj.Getfolder(Chem)
If Microsoft.VisualBasic.Left(Rep.Name, 1) = "$" Then GoTo Passe2
sRep = Rep.subfolders
For Each sRp In sRep
S = UCase(sRp.Name)
If Trouver <> "" Then Exit For
If Microsoft.VisualBasic.Left(S, 1) = "$" Or S = "WINDOWS" Or sRp.Attributes = 19 _
Or Microsoft.VisualBasic.Left(S, 6) = "SYSTEM" Or Microsoft.VisualBasic.Left(S, 7) = "PROGRAM" Or Microsoft.VisualBasic.Left(S, 4) = "USER" _
Or Microsoft.VisualBasic.Left(S, 6) = "DRIVER" Or Microsoft.VisualBasic.Left(S, 5) = "TOOLS" Then GoTo Passe
On Error Resume Next
sR2 = sRp.subfolders
NbsR = sR2.Count
If Err.Number <> 0 Then GoTo Passe
sCle = sRp.Path & IIf(Microsoft.VisualBasic.Right(sRp.Path, 1) <> "\", "\", "")
Trouver = Dir(sCle & Cherche)
If Trouver <> "" Then Trouver = sCle & Trouver : Exit Sub
On Error GoTo 0
If NbsR > 0 Then
LireRep(sCle)
End If
Passe:
Next
Passe2:
Obj = Nothing
Rep = Nothing
sRep = Nothing
sR2 = Nothing
End Sub
-----------------------------------
كد فراخواني اين Sub توسط button1 همراه با مديريت خطا ها و مديريت پيامها
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Me.Label2.Text = "لطفا صبر كنيد..."
Me.ProgressBar1.Visible = True
Me.Refresh()
Trouver = ""
Cherche = Trim(TextBox1.Text)
If Cherche = "" Then
Me.Label2.Text = "كدام فايل را جستجو كنم؟"
Me.ProgressBar1.Visible = False
Me.TextBox1.Focus()
Exit Sub
End If
LireRep(Me.ComboBox1.Text)
If Trouver <> "" Then
Label1.Text = Trouver
Me.Label2.Text = "نتيجه"
Me.ProgressBar1.Visible = False
Else
Label1.Text = "None"
Me.Label2.Text = "فاقد اطلاعات"
Me.ProgressBar1.Visible = False
End If
Catch ex As Exception
Me.Label1.Text = ex.ToString
Me.Label2.Text = "خطا در جستجو"
Me.ProgressBar1.Visible = False
End Try
End Sub
----------------------------
بقيه در پست بعد
حتما تا حلا پيش اومده كه دنبال يك فايل در سيستم بگردين كه يادتون رفته كجا ذخيره اش كردين؟
در اين مواقع زياد خودنون رو ناراحت نكنين ، اين تاپيك رو بخونين و زود دست بكار بشين:لبخندساده:
در اين تاپيك قصد دارم نحوه ساخت و كد نويسي يك برنامه مفيد رو كه كارش پيدا كردن يك فايل در سيستم هستش ، براتون آموزش بدم
البته با امكانات ويندوز هم ميشه اين كار رو انجام داد منتها ساخت اين برنامه خالي از لطف نيست:بامزه:
**********************
كنترل هاي مورد نياز
------------------------
Button1 جهت شروع جستجو
خصوصيات : پيش فرض
------------------------
Button2 جهت اجراي فايل پيدا شده درصورت نياز
خصوصيات : Enabled= False
------------------------
Label1 جهت نمايش مسير فايل
خصوصيات : text=""
-------------------------
Label2 جهت نمايش پيام سيستم به كاربر
خوصوصيات: با رنگ متفاوت (قرمز) و فونت درشت و text = ""
-------------------------
ComboBox1 جهت نمايش درايو هاي موجود در سيستم
خصوصيات : DropDownStyle = DropDownList
------------------------
ProgerssBar1 جهت نمايش فرايند جستجو
خصوصيات : Visible= False , Style=Marquee
-------------------------
TextBox1 جهت گرفتن نام و پسوند فايل مورد نظر
خصوصيات : پيش فرض
--------------------------
يك فرم به ابعاد 400*300 يا .....
********************************
كد هاي مربوط به فرم لود جهت ليست كردن درايو هاي موجود كه البته يك Function هم دارد :
Imports System.IO
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim sDrive As String, sDrives() As String
sDrives = ListAllDrives()
For Each sDrive In sDrives
Debug.WriteLine(sDrive)
Next
Me.ComboBox1.Items.AddRange(ListAllDrives())
Me.ComboBox1.SelectedIndex = 1
End Sub
Public Function ListAllDrives() As String()
Dim arDrives() As String
arDrives = Directory.GetLogicalDrives()
Return arDrives
End Function
ايندكس كمبو باكس رو بخاطر اين 1 گرفتم كه در ليست درايو ها اولين درايو A و دومين C هست كه هنگام لود شدن بهتره درايو C پيش فرض باشه
------------------------------------------------
كد اصلي جستجو در قالب يك Sub كه بعدا قراره توسط Button1 فراخواني بشه:
Dim Trouver As String
Dim Cherche As String
Sub LireRep(ByVal Chem As String)
Dim Rep, sRp, Obj, sRep, sR2
Dim sCle As String
Dim NbsR As Integer, S As String
Chem = Chem & IIf(Microsoft.VisualBasic.Right(Chem, 1) = "\", "", "\")
Trouver = Dir(Chem & Cherche)
If Trouver <> "" Then Trouver = Chem & Trouver : Exit Sub
'--------------------------------------
Obj = CreateObject("Scripting.FileSystemObject")
Rep = Obj.Getfolder(Chem)
If Microsoft.VisualBasic.Left(Rep.Name, 1) = "$" Then GoTo Passe2
sRep = Rep.subfolders
For Each sRp In sRep
S = UCase(sRp.Name)
If Trouver <> "" Then Exit For
If Microsoft.VisualBasic.Left(S, 1) = "$" Or S = "WINDOWS" Or sRp.Attributes = 19 _
Or Microsoft.VisualBasic.Left(S, 6) = "SYSTEM" Or Microsoft.VisualBasic.Left(S, 7) = "PROGRAM" Or Microsoft.VisualBasic.Left(S, 4) = "USER" _
Or Microsoft.VisualBasic.Left(S, 6) = "DRIVER" Or Microsoft.VisualBasic.Left(S, 5) = "TOOLS" Then GoTo Passe
On Error Resume Next
sR2 = sRp.subfolders
NbsR = sR2.Count
If Err.Number <> 0 Then GoTo Passe
sCle = sRp.Path & IIf(Microsoft.VisualBasic.Right(sRp.Path, 1) <> "\", "\", "")
Trouver = Dir(sCle & Cherche)
If Trouver <> "" Then Trouver = sCle & Trouver : Exit Sub
On Error GoTo 0
If NbsR > 0 Then
LireRep(sCle)
End If
Passe:
Next
Passe2:
Obj = Nothing
Rep = Nothing
sRep = Nothing
sR2 = Nothing
End Sub
-----------------------------------
كد فراخواني اين Sub توسط button1 همراه با مديريت خطا ها و مديريت پيامها
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
Me.Label2.Text = "لطفا صبر كنيد..."
Me.ProgressBar1.Visible = True
Me.Refresh()
Trouver = ""
Cherche = Trim(TextBox1.Text)
If Cherche = "" Then
Me.Label2.Text = "كدام فايل را جستجو كنم؟"
Me.ProgressBar1.Visible = False
Me.TextBox1.Focus()
Exit Sub
End If
LireRep(Me.ComboBox1.Text)
If Trouver <> "" Then
Label1.Text = Trouver
Me.Label2.Text = "نتيجه"
Me.ProgressBar1.Visible = False
Else
Label1.Text = "None"
Me.Label2.Text = "فاقد اطلاعات"
Me.ProgressBar1.Visible = False
End If
Catch ex As Exception
Me.Label1.Text = ex.ToString
Me.Label2.Text = "خطا در جستجو"
Me.ProgressBar1.Visible = False
End Try
End Sub
----------------------------
بقيه در پست بعد