PDA

View Full Version : جستجوی تمام هارد برای txt



xrezax
سه شنبه 30 آبان 1391, 00:07 صبح
دوستان سورسی می خوام که باهاش بتونم تمام هارد را جستجو کنم و فایل های txt را لیست کنم توش.

farazjalili
سه شنبه 30 آبان 1391, 01:09 صبح
این لینک رو یه نگاهی بی انداز البته به زبان C# هست :
http://stackoverflow.com/questions/2437716/search-text-file-using-c-sharp-and-display-the-line-number-and-the-complete-line

farazjalili
سه شنبه 30 آبان 1391, 01:10 صبح
این لینک رو یه نگاهی بی انداز البته به زبان C# هست :
http://stackoverflow.com/questions/2437716/search-text-file-using-c-sharp-and-display-the-line-number-and-the-complete-line
اینم ببین :
http://stackoverflow.com/questions/1225294/c-sharp-find-a-file-within-all-possible-folders

gilsoft
سه شنبه 30 آبان 1391, 08:13 صبح
دوستان سورسی می خوام که باهاش بتونم تمام هارد را جستجو کنم و فایل های txt را لیست کنم توش.

سلام دوست عزیز

Imports VB = Microsoft.VisualBasic
Imports System.IO

Module Module1
Public Function FindSpecialExtenionFiles(Ext As String, Optional DriveType As DriveType = DriveType.Fixed) As String()
If VB.Left(Ext.Trim, 2) <> "*." Then Ext = "*." & Ext.Trim
Dim FileList As New List(Of String)
For Each Drive As DriveInfo In DriveInfo.GetDrives
If Drive.DriveType = DriveType AndAlso Drive.IsReady Then
GetAllFiles(Drive.Name, Ext, FileList)
End If
Next
FindSpecialExtenionFiles = (FileList.ToArray)
FileList.Clear()
End Function 'FindSpecialExtenionFiles

Private Sub GetAllFiles(Drive As String, Ext As String, FileList As List(Of String))
For Each File As String In Directory.GetFiles(Drive, Ext)
FileList.Add(File)
Next
For Each Dir As String In Directory.GetDirectories(Drive)
Try
GetAllFiles(Dir, Ext, FileList)
Catch ex As Exception
End Try
Next
End Sub 'GetAllFiles
End Module

نحوه ی اسفاده از تابع :

اول یه RichTextBox .. یه Label .. و یه Button به فرم اضافه کن
بعد کد زیر رو توی فرم کپی کن

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click

Dim FileList() As String
FileList = FindSpecialExtenionFiles("TXT", DriveType.Fixed)

For Each s As String In FileList
RichTextBox1.Text &= s & vbCrLf
Next
RichTextBox1.Refresh()

Label1.Text = FileList.Count.ToString & " File(s) Find ..."
End Sub

موفق باشید

xrezax
سه شنبه 30 آبان 1391, 13:25 عصر
چطور بجای RichTextBox1 از listbox1 استفاده کنم ؟؟؟

asghar2008
سه شنبه 30 آبان 1391, 13:47 عصر
چطور بجای RichTextBox1 از listbox1 استفاده کنم ؟؟؟


سلام
با دستور زیر :
ListBox1.Items.Add(s)