ҡդӶ ʵŧ 纺촨շ٨絴͵ ᷹ФѺ

͵Դҷҧ Inbox Ѻ

˹ѡ
-
VB 6/VB.Net
ASP/ASP.Net
Ѻ¤
¹ҹ Flash Movie
ռͺش  
 RSS Feeds
 ǹŴ RSS Reader ...   Download  RSS Reader

Forum - www.g2gnet.com
Webmaster - www.g2gnet.com
Visitors - Session views
 5 6 1 6 1 1 5

7 ѹҤ ..2549
69 Users On-Line.
Visitors - Page views
 8 9 7 3 8 5 8
1 Ҿѹ ..2551

Google   
g2gnet.com
Ҵѡ:  

ҹ Remove Drive (Flash/Thumb/Handy Drive) Ҥ 2 - º

Category »  VB 6/VB.Net
: Webmaster 1/3/2552   : 18:01
(ҹ : 14669) 
Ѳҡâͧ㹻Ѩغѹ ӹ˹ҡ͹ ҹ¢ ѹ͹Һ 2 ҨзѡѲҫͿ ԴѺѡҧ ѡ١ҷҧý֡ ҡҷн֡¹ ... ¡ҧ ùҾҿԤѡٻʴ Visual ҡ Control ҧ سѵŧ Թ觹ҷաҨº ҡ C (DOS) سеͧѡسѵԢͧҾҧ ѹբҴԵ кԵդҧ 件֧èѺͧ鹷˹¤ (Allocation) ͹ǧ˹ ҹ繵 ... ... 觷ҹ 繶֧ͧǢͧ "šԷ - Algorithm" "ԸաäԴ ӴѺ鹵͹" 㹡ѭ ǧѧҹ ͧ ѹ¤͹ҧͧкǹäԴѡ˭
ǤԴͧҹ Remove Drive Ẻѵѵ ... Algorithm Ẻҹ
    ¤ҨЧ ʧ ... ѹԴѧ䧢ͧѹ () ... ¨ѧ ... 55555+
  • Ѵ͡ Drive C: D: ҡ DriveListBox ListView 觨ж١͹ (Visible = False)
  • Timer ء 1 Թҷ (ǡҹ) ҹ Drive Դҧ DriveListBox Refresh DriveListBox ͧ
  • ºº Drive ҧҡ DriveListBox Drive ListView (ͧ 2 ٻ 㹡õǨͺ)
    1. ҡ Drive DriveListBox ListView ... ʴաº Removable Drive
    2. ҡ Drive DriveListBox ListView ... ʴաöʹ Removable Drive ͡
  1. Project --> References ...
  1. Project --> Components ...
  1. Design Time
  2. Ѻ Properties ͧ List View Control (lvwViewer)
    Style = 1 - CheckBox
ǹŴ Source Code Ѻ MS Visual Basic 6.0 - Service Pack 6
 ǹŴ Visual Basic 6.0 SP5: Run-Time Redistribution Pack
 ǹŴ Microsoft Data Access Object (MDAC) Jet 4.0 Update
 ǹŴ Microsoft Visual Basic Service Pack 6

 ҹ Remove Drive (Flash/Thumb/Handy Drive) Ҥ 1 (ҹ͹оͧ)
鹡кǹ÷ӧҹ

Private Sub Timer1_Timer()
    ' ºº Drive ҡ DriveListBox Ѻ ListView ҷ  ء 1000 millisecond (1 Թҷ)
    Call RefreshDrives
End Sub

' 㹡ºº Drive ҡ DriveListBox Ѻ ListView
Private Sub RefreshDrives()
Dim DrvDet As Integer '  Drive Detect Ǩͺ Drive ҡ DriveListBox
Dim DrvChk As Integer ' Drive Check ѡ Drive 
Dim DriveFlag As Boolean ' áзա  ʹ Removeable Drive 

' ҹ Drive  DriveListBox ͹ ... ҷ
DriveDetect.Refresh

' ººӹǹ DriveListBox Ѻ ListView
' ͹ ԧ ... ʴաù Removable Drive 
If DriveDetect.ListCount > lvwDrives.ListCount Then
  
    ' ٻǧ͡شѺӹǹ Drive ҡ DriveListBox
    For DrvDet = 0 To DriveDetect.ListCount
        ' ٻǧ㹤͡÷ͺ Removable Drive ˹
        For DrvChk = 0 To lvwDrives.ListCount
            
            ' ҡդҡѹ͡ҡٻ (DrvChk)  ʴ Drive 
            If lvwDrives.List(DrvChk) = DriveDetect.List(DrvDet) Then
                DriveFlag = False
                Exit For
                
            ' ó "" Դ 2 ó 
            ' 1. ºº Drive çѹԧ ѧ ٻ͡͹
            ' 2. ººçѹ   ʴԴ Removable Drive 
            ' 㹢ͷ 2 Դشҡٻ͡ (DrvDet) ͹ DriveFlag = ԧ 
            Else
                DriveFlag = True
            End If
        ' ѹ 2 ٻ ... ͵͹ (DrvChk) ҵͷ ͷ觧  ...
        ' ¡ѹ Nested Loop ...  ǧͺͧ㹢ͧաٻ ... ٻ͹ٻ
        Next DrvChk
        
        ' ҡóշ 2 ҹ ... ѹ Removable Drive 
        If DriveFlag Then
            ' ¡ Drive 价 lvwDrives (ListView Control Ƿ͹)
            lvwDrives.AddItem DriveDetect.List(DrvDet)
            
            'Debug.Print "Found New Drive: " & DriveDetect.List(DrvDet)
            
            ' 觪 Drive 价ͺ͹繻 Removable Drive 
            ' ҡ¡ҧ ListView (ѧ AddToListView)
            If CheckRemovable(Left$(DriveDetect.List(DrvDet), 2)) Then _
                    Call AddToListView(UCase$(Left$(DriveDetect.List(DrvDet), 2)))
        End If
    
    ' ѹ 2 ٻ ... ͵͹ (DrvDet) ҵͷ ͷ觧 ...
    Next DrvDet
  
' ͹  ... ʴաù Removable Drive ͡仨ҡͧ
ElseIf DriveDetect.ListCount < lvwDrives.ListCount Then

    ' ӧҹѺҹѹѺ͹ "ԧ" ФѺ ... ͧ
    ' ٻǧ͡شѺӹǹ Drive ҡ ListView Control ͹ (lvwDrives)
    For DrvDet = 0 To lvwDrives.ListCount
    
        ' ٻǧ㹤͡÷ͺ Removable Drive ˹١ʹ͡
        For DrvChk = 0 To DriveDetect.ListCount
            
            ' ҡդҡѹ͡ҡٻ (ʴ Drive )
            ' ͸Ժ¨͹ѹѺ Removable Drive 
            If DriveDetect.List(DrvChk) = lvwDrives.List(DrvDet) Then
                DriveFlag = False
                Exit For
            Else
                DriveFlag = True
            End If
        
        Next DrvChk
    
        If DriveFlag Then
            'Debug.Print "Drive Has Been Removed: " & lvwDrives.List(DrvDet)
            
            ' ͧǨͺѹ Removable Drive  ... ʹѹ͡仡ѹ ... 
            'If CheckRemovable(UCase$(Left$(lvwDrives.List(DrvDet), 2))) Then _
                        Call RemoveFromListView(UCase$(Left$(lvwDrives.List(DrvDet), 2)))
            
            ' ź¡͡ҡ ListView Control (lvwViewer)
            Call RemoveFromListView(UCase$(Left$(lvwDrives.List(DrvDet), 2)))
            
            ' ź¡ Drive ͡ҡ ListView Control Ƿ͹ lvwDrives
            lvwDrives.RemoveItem DrvDet
        End If
    Next DrvDet
End If

End Sub

'  Remove Drive  ͧª -   ListView (lvwViewer)
Private Function AddToListView(Drive As String)
    
    Set mDrive = FSO.GetDrive(Drive)
    If mDrive.DriveType = Removable And mDrive.IsReady = True Then
        For Each mFile In mDrive.RootFolder.Files
            DoEvents
            lvwViewer.AddItem mFile.Path
            nFiles = nFiles + 1
        Next
        
        ' ѹ¡èӹǹѺ
        fraViewer.Caption = " ӹǹ " & nFiles & " " & " "
        
        ' ¡ҷ
        For Each mFolder In mDrive.RootFolder.SubFolders
            DoEvents
            ' ʴ͡
            lvwViewer.AddItem mFolder.Path
            nFolders = nFolders + 1
        Next
        
        ' ǹͧùѺӹǹ
        fraViewer.Caption = fraViewer.Caption & " / ӹǹ " & nFolders & " " & " "
        
    End If
End Function

' աöʹ Remove Drive ͡ ͧª -  ͡ҡ ListView (lvwViewer)
Private Function RemoveFromListView(Drive As String)
Dim sRow As Integer
Dim CountRow As Integer
    
    CountRow = lvwViewer.ListCount - 1
    For sRow = 0 To CountRow
        If UCase$(Left$(lvwViewer.List(sRow), 2)) = Drive Then
            ' йѺҨҡҧش 3 ѡ ǶѴҡ繨ش (Dot)  ... ѹ
            If Mid$(lvwViewer.List(sRow), Len(lvwViewer.List(sRow)) - 3, 1) = "." Then
                nFiles = nFiles - 1
            Else
                nFolders = nFolders - 1
            End If
            
            lvwViewer.RemoveItem sRow
            CountRow = lvwViewer.ListCount - 1
            sRow = lvwViewer.ListIndex - 1
        End If
    Next
    
    fraViewer.Caption = " ӹǹ " & nFiles & " " & " / ӹǹ " & nFolders & " " & " "
End Function

' ѧ蹵Ǩͺ Drive ҹ Removable Drive 
' ҡ ׹ҡѺ True ... ׹ False
Public Function CheckRemovable(Drive As String) As Boolean
On Error Resume Next
    Set mDrive = FSO.GetDrive(Drive)
    If mDrive.DriveType = Removable And mDrive.IsReady = True Then
        CheckRemovable = True
    Else
        CheckRemovable = False
    End If
End Function
Conclusion:
2 ͹ѧǹ ... ͧöѹ任ءҹ㹡ôѡ ֧ʧ¤Ѻ ... ҧº 任µ͡ѧ 55555+ ѹͧ͡ҧ ҧͧ ... ǹѹҧ¼⫴ҤѺ ... йҢ ǡѺͧԷ (Rights) кѡҤʹк (Security) к ... Ѻм
͵ - g2gNet Dot Com
Ţ¹ҳԪ硷͹ԡ 0407314800231
CopyLeft © 2004 - 2099 g2gNet.Com All rights reserved.
Email: [email protected] . 08-6862-6560