just4froum
سه شنبه 12 مهر 1390, 21:01 عصر
با سلام
آیا راهی هست که بدون استفاده از filelistbox لیست تمام فایل های موجود در یک دایرکتوری خاص را پیدا کنیم و در یک آرایه ذخیره کنیم ؟؟؟
(البته بدون استفاده از shell)
با تشکر از همگی
sajjad_india
سه شنبه 12 مهر 1390, 21:46 عصر
راه حل های جابی هست واسه این کار .
1 - میتونید از فایل دایکتوری استفادی کنی و مسیر رو تعریف کنی بعد اینکه فایل ها رو از اون بخونی و تو یه لیست باکسی اضافه کنی که این بهتره به نظر من . میتونی بیشتر مانور بدی واسه این کار .
2- یا از کد زیر :
'Just add a listbox (List1)
Private Sub ListFiles(strPath As String, Optional Extention As String)
'Leave Extention blank for all files
Dim File As String
If Right$(strPath, 1) <> "\" Then strPath = strPath & "\"
If Trim$(Extention) = "" Then
Extention = "*.*"
ElseIf Left$(Extention, 2) <> "*." Then
Extention = "*." & Extention
End If
File = Dir$(strPath & Extention)
Do While Len(File)
List1.AddItem File
File = Dir$
Loop
End Sub
Private Sub Form_Load()
ListFiles "C:\", "txt"
End Sub
3 -
Public Function ListFiles(FolderPath As String, Extension As String, LstObj As ListBox)
Dim i As Long
Dim FolderName As String
Dim DirNames() As String
Dim SubDirectories As Long
'List files in the main/first folder
FolderName = Dir(FolderPath & "\" & Extension, vbNormal)
Do While FolderName <> vbNullString
LstObj.AddItem FolderPath & "\" & FolderName
FolderName = Dir()
Loop
'Get the sub directories
FolderName = Dir(FolderPath & "\*.*", vbDirectory)
Do While FolderName <> vbNullString
If FolderName <> "." And FolderName <> ".." Then
SubDirectories = SubDirectories + 1
ReDim Preserve DirNames(1 To SubDirectories)
DirNames(SubDirectories) = FolderName
End If
FolderName = Dir()
Loop
For i = 1 To SubDirectories
ListFiles FolderPath & "\" & DirNames(i), Extension, LstObj
Next i
End Function
Private Sub Command1_Click()
ListFiles "C:\SomeFolder", "*.img", List1
End Sub
و هزاران راه حل دیگه . برنامه نمیزارم تا بری دنبالش یاد بگیری و 10 تا چیز دیگه هم تو سرچ میتونی یاد بگیری . :قلب:
vBulletin® v4.2.5, Copyright ©2000-1403, Jelsoft Enterprises Ltd.