VB.Net - Poiščite datoteko na trdem disku

Ta demo vam omogoča iskanje po trdem disku (ne da bi vedel pot).

  • Na obrazcu, TextBox (TextBox1) in oznaka (Label1)
  • Kopirajte / prilepite kodo v modul obrazca.

Koda

 Javni razred Form1 Dim dimencer kot niz Nizka Cherche Kot niz Sub LireRep (ByVal Chem As String) Dim Rep, sRp, Obj, sRep, sR2 Dim sCle Kot niz Dim NbsR Kot Integer, S kot niz Chem = Chem & IIf (Microsoft.VisualBasic . Pravica (Chem, 1) = ", " ", " ") ------- au cas ou ce serait dans le DD Trouver = Dir (Chem & Cherche) Če je" "Potem" Chem & Trouver: Exit Sub '-------------------------------------- Obj = CreateObject (" Scripting.FileSystemObject ") Rep = Obj.Getfolder (Chem) Če je Microsoft.VisualBasic.Left (Rep.Name, 1) =" $ ", potem GoTo Passe2 sRep = Rep.subfolders za vsak sRp V sRep S = UCase (sRp.Name ) 'sortir de la boucle précédante si le fichier est trouver Če je Trouver "" Potem Exit For' ------------ Elimine les répertoires système Če Microsoft.VisualBasic.Left (S, 1) = "$ "Ali S =" WINDOWS "Ali sRp.Attributes = 19 _ Ali Microsoft.VisualBasic.Left (S, 6) =" SISTEM "Ali Microsoft.VisualBasic.Left (S, 7) =" PROGRAM "ali Microsoft.VisualBasic.Left (S, 4) = "USER" _ ali Microsoft.VisualB asic.Left (S, 6) = "DRIVER" Ali Microsoft.VisualBasic.Left (S, 5) = "TOOLS" Potem GoTo Passe On Error Nadaljuj 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) Če je preusmerjevalnik" "nato usmerjevalnik = sCle & Odjemalec: Izhod Pod napako GoTo 0 Če je NbsR> 0 Potem 'predavanje récursive des sous-réperto! Res LireRep (sCle) End Če Passe: Next Passe2:' libère la mémoire Obj = Nič Rep = Nič sRep = Nič sR2 = Nič ne konča Sub Zasebno Sub Button1_Click (ByVal pošiljatelj Kot System.Object, ByVal e kot System.EventArgs) Ročaji Button1.Click Trouver = "" Cherche = Trim (TextBox1.Text) Če Cherche = "" Potem Izhod Sub LireRep ("c: \ t ) Če je nato "" "" "" "" "" "" "" "" "" "" "" "" "" "" "". \ T 

Prenesi

Prenesi datoteko

Prejšnji Članek Naslednji Članek

Top Nasveti