Windows
Scripts
VBScript
Rechercher un fichier
Pour : Windows
On va voir comment faire pour rechercher un fichier sur le disque dur.
Par exemple on va rechercher tous les fichiers "toto" sur le lecteur "C:\".
Exemple:
'*** Configuration des variables d'environnement Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set Shell = CreateObject("wscript.Shell") Set env = Shell.environment("Process") strComputer = env.Item("Computername") set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colFiles = objWMIService.ExecQuery ("Select * from CIM_DataFile Where FileName = 'toto' and Drive = 'C:'") For Each objFile in colFiles Wscript.Echo "Dossier => " & objFile.Drive & objFile.Path Wscript.Echo "Nom => " & objFile.FileName & "." & objFile.Extension Wscript.Echo "Taille => " & objFile.FileSize & " Octets" Next '*** Destruction des objets Set fso = Nothing Set Shell = Nothing Set env = Nothing WScript.Quit
'*** Configuration des variables d'environnement Set fso = WScript.CreateObject("Scripting.FileSystemObject") Set Shell = CreateObject("wscript.Shell") Set env = Shell.environment("Process") strComputer = env.Item("Computername") set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") set colFiles = objWMIService.ExecQuery ("Select * from CIM_DataFile Where FileName = 'toto' and Extension = 'txt' and Drive = 'C:'") '*** Affichage de la recherche avec l'aide d'une boucle "For" For Each objFile in colFiles Wscript.Echo "Dossier => " & objFile.Drive & objFile.Path Wscript.Echo "Nom => " & objFile.FileName & "." & objFile.Extension Wscript.Echo "Taille => " & objFile.FileSize & " Octets" Next '*** Destruction des objets Set fso = Nothing Set Shell = Nothing Set env = Nothing WScript.Quit