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
| ' doit être appelé par cscript pour avoir la console
option explicit
Dim stRep 'Nom du répertoire à parcourir
dim WshShell, Mdoc
Set WshShell = WScript.CreateObject("WScript.Shell")
Mdoc = WshShell.SpecialFolders("MyDocuments")
strep= Mdoc & "\Fichiers BAS\Rech_films"
dim trouve ,nf
Dim oFSO,oFl, fic, arg, fin
Set oFSO = CreateObject("Scripting.FileSystemObject")
If not oFSO.FolderExists(stRep) Then
msgbox strep,vbcritical,"Répertoire non trouvé" : wscript.quit
end if
do
'c'est ici que je veux effacer le contenu
trouve = false : nf=0
arg = inputbox("Partie du titre de films", _
"Ne rien saisir pour sortir","?")
fin=(arg="")
if not fin then recherche arg
loop until fin
'----------------------------------------------------------------
sub recherche (arg)
For each oFl in oFSO.GetFolder(stRep).Files
fic = oFl.Name
if left(fic,5)="Liste" and oFl.type="Document texte" then
if rfic(oFl.path,arg) then trouve = true
end if
Next
if trouve then
msgbox nf & " films trouvés",,"Recherche: " & arg
else
msgbox "Pas de film trouvé pour cet argument",,arg
end if
end sub
'----------------------------------------------------------------
function rfic(fl,argu)
Const ForReading = 1
dim lig, titre, genre, taille, x
Dim f : Set f = oFso.OpenTextFile(fl, ForReading)
while Not f.AtEndOfStream
lig=f.ReadLine
x=instr(1,lig,";")
if x>0 then
titre=left(lig,x-1)
if instr(1,titre,argu,vbtextcompare)> 0 then
lig=mid(lig,x+1)
x=instr(1,lig,";")
genre=left(lig,x-1)
taille= mid(lig,x+1)
wscript.echo fic
wscript.echo string(len(fic),"=")
wscript.echo titre & vblf & genre & vblf & taille & vblf & ""
rfic=true
nf=nf+1
end if
end if
Wend
f.Close
end function |
Partager