1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
'+-----------------------------------------------------------------------------------------+
'+ Ce script utilise une fonction récursive pour parcourir l'ensemble des repertoires du +
'+ disque dur afin de déterminer l'ensemble des données suivante pour chaque fichier: +
'+ - chemin +
'+ - taille +
'+ - propriétaire +
'+ - date de création +
'+ - date de modification +
'+ By pierre xavier +
'+-----------------------------------------------------------------------------------------+
Option Explicit
'********************************INITIALISATION****************************
dim PathResultat
PathResultat = InputBox("Choissez le fichier de sortie:")
Dim path_start
Dim Myfso, result
Set Myfso = CreateObject("Scripting.FileSystemObject")
path_start = InputBox("Choisissez le repertoire de début de recherche (ne pas mettre de \ a la fin):")
'***************************LANCEMENT DE LA RECHERCHE****************************
result = Find(path_start)
wscript.echo "fin de la recherche"
'*********************fonction de recherche recursive********************
Function Find (strPath)
on error resume next
Dim MyDir, MyFile, MySubDir
Dim strResult
Dim user, Path
Set MyDir = Myfso.GetFolder(strPath)
wscript.echo parsePath(strPath)
For Each MyFile In MyDir.Files
Path = parsePath(strPath &"\"& MyFile.Name)
user = getOwner(Path)
wscript.echo "fichier --> " & Path
strResult = strResult & "insert into states(chemin,nom,taille,owner,date_create,date_modif,GEN) values('"& parsePath(strPath) & "','" & MyFile.Name &"','"& MyFile.Size & "','"& user & "','" &MyFile.DateCreated&"','"& MyFile.DatelastModified & "', (SELECT GEN_ID(GEN_STATES, 1) FROM RDB$DATABASE));"&vbCrLf
Next
Call WriteLineToFile(strResult,PathResultat)
For Each MySubDir In MyDir.SubFolders
'appel récursif
strResult = strResult & Find(strPath & "\" & MySubDir.Name)
Next
Find = strResult
End Function
'***************FONCTION DE RECUPERATION DU PROPRIETAIRE DU FICHIER**************
Function getOwner(strFile)
'on error resume next
Dim objWMIService
Dim objSD
Dim intRetVal
Dim objFileSecuritySettings
Set objWMIService = GetObject("winmgmts:")
Set objFileSecuritySettings = objWMIService.Get("Win32_LogicalFileSecuritySetting='" & strFile &"'")
intRetVal = objFileSecuritySettings.GetSecurityDescriptor(objSD)
If intRetVal = 0 Then
Else
wScript.Echo "Impossible de récupérer le descripteur de sécurité."
End If
getOwner = objSD.Owner.Name
End Function
'*****************FONCTION D'ECRITURE DANS UN FICHIER***************************
Sub WriteLineToFile (str, path)
Const ForReading = 1, ForWriting = 2 ,ForAppending = 8
Dim fso, f
Set fso = CreateObject("Scripting.FileSystemObject")
Set f = fso.OpenTextFile(path, ForAppending, True)
f.WriteLine str
End Sub
'********************Parse une string pour appliquer le bon format (suppression des //)******************
Function parsePath(str)
parsePath = Replace(str,"\\", "\")
parsePath = Replace(str,"\\\", "\")
parsePath = Replace(str,"\\\\", "\")
end Function |
Partager