If exist "nom dans un fichier"

Fermé
fabien - 6 nov. 2009 à 10:38
OlivrT Messages postés 323 Date d'inscription lundi 2 novembre 2009 Statut Membre Dernière intervention 24 mai 2012 - 6 nov. 2009 à 15:00
Bonjour,
je suis entrain d'écrire un script en vbs et je bloque sur : si "fabien" existe dans le fichier listenom.txt
Il y a cette commande pour vérifier si un fichier existe , mais moi c'est le contenu que je souhaiterai vérifier
Set objFSO = CreateObject("Scripting.FileSystemObject" )
If objFSO.FileExists("listenom.txt" )

Merci pour votre aide !
A voir également:

4 réponses

OlivrT Messages postés 323 Date d'inscription lundi 2 novembre 2009 Statut Membre Dernière intervention 24 mai 2012 36
6 nov. 2009 à 11:25
si j'ai bien compris ... tu parcours ton fichier et si tu ne trouves pas "Fabian" tu veux executer une appli ?
Je serai toi, je metterai une variable à zéro : NomTrouve=0
Si après après lu ton fichier cette variable est toujours à zéro, tu lances ton appli :
Set objShell = CreateObject("WScript.Shell")
strCommand = "c:\MesProgrammes\Fabian.exe"
objShell.Run strCommand
1
Yes ! Sa marche en affectant une variable. Un grand merci !
0
OlivrT Messages postés 323 Date d'inscription lundi 2 novembre 2009 Statut Membre Dernière intervention 24 mai 2012 36
6 nov. 2009 à 10:48
Salut,
voici :
Dim filesys, text, MonFichier, Ligne
Set filesys = CreateObject("Scripting.FileSystemObject")
Set MonFichier = filesys.OpenTextFile("c:\Monfichier.txt", 1, False)
Do While MonFichier.AtEndOfStream = False
Ligne = MonFichier.ReadLine
'tu cherches ton nom dans MaLigne

Loop
MonFichier.Close
0
merci pour ta reponse
j'avais déja fait cette commande mais du cou pour le nom comparé (ofld.name) il me traite une reponse pour chaque ligne
exemple : j'ai un fichier txt contenant :
test
test1
fabien
test2

je souhaiterai que si fabien n'est pas dans ce fichier txt alor qu'il me fasse une certaine apli, mon probleme est que il va me lancer l'appli pour test, test1, test2 vu qu'ils son diferent de fabien.
Je sais pas si j'ai été très claire ! ;)

Set oFso = CreateObject("Scripting.FileSystemObject")
Set Ftxt = oFso.OpenTextFile(strCurrentDir & "Blacklist.txt")


if NoExist_Blacklist_User(MaVariable_ligne) then
wscript.echo "l'utilisateur existe"

else

wscript.echo "non trouvé ou reference blacklist"


Private Function NoExist_Blacklist_User(MaVariable_ligne)
'on parcours chaque ligne du fichier texte
Do While Not Ftxt.AtEndOfStream

MaVariable_ligne = Ftxt.Readline
' WScript.Echo "VALEUR LIGNE LU ==> " & MaVariable_ligne

' On la compare au nom du repertoire trouve
If MaVariable_ligne = oFld.Name Then
WScript.Echo " Nom repertoire : " & oFld.Name & " ==> Trouve dans blacklist "
NoExist_Blacklist_User = False
Else
WScript.Echo " Nom repertoire : " & oFld.Name & " ==> Autorise "
NoExist_Blacklist_User = True
End If

Loop

' fermeture du fichier
Ftxt.Close
0
OlivrT Messages postés 323 Date d'inscription lundi 2 novembre 2009 Statut Membre Dernière intervention 24 mai 2012 36
6 nov. 2009 à 15:00
;-) Change le statut du call stp, comme "Résolu".
0