Twitter iPhone pliant OnePlus 11 PS5 Disney+ Orange Livebox Windows 11

[debutant] tester l'existance d'un fichier

4 réponses
Avatar
Azur
Bonjour,



Je cherche à tester en vbscript la presence d'un fichier (robocopy.exe) sans
en connaitre sa position réelle.

Je vousdrais utiliser pour cela la variable d'environnemnt PATH
qui contient bien le chemin d'accès au resssource kit dans lequel figure
robocopy.exe

dans mon programme si je fais un ...FileExists("%PATH%\robocopy.exe")
cela ne fonctionne pas et j'en conviens...


Les differents chemin d'accès de la variable PATH path son séparés par des
point-virgules
comment les exploiter simplement avec un script ?


-azur-

4 réponses

Avatar
Méta-MCI \(MVP\)
Salut !


Deux façons (parmi d'autres) de tester si robocopy est là :


Là, on a un affichage parasite, si absent :
echo off

robocopy /? >null
IF ERRORLEVEL 9000 GOTO :ABSENT
echo Il est bien ici, et utilisable.
goto :EOF

:ABSENT
cls
echo Il n'est pas ici (ou en grêve)
::goto :EOF



Ici, on teste si les Reskit/Robocopy a été installé. Attention, le
programme peut avoir été installé/copié autrement. Et, sous Vista,
Robocopy est présent d'origine :

:EOF
reg query HKCUSoftwareMicrosoftResKitRobocopy /v JobDir >null
if ERRORLEVEL 1 goto :ERR
echo Installed
goto :EOF

:ERR
cls
echo Not_installed




@+

Michel Claveau
Avatar
Azur
Effectivement, c'est plus simple avec la gestion d'erreur.


Je choisi la 1ere solution

merci de ton aide.



-azur-




"Méta-MCI (MVP)" a écrit dans le message
de news: 474adc2a$2$27385$
Salut !


Deux façons (parmi d'autres) de tester si robocopy est là :


Là, on a un affichage parasite, si absent :
echo off

robocopy /? >null
IF ERRORLEVEL 9000 GOTO :ABSENT
echo Il est bien ici, et utilisable.
goto :EOF

:ABSENT
cls
echo Il n'est pas ici (ou en grêve)
::goto :EOF



Ici, on teste si les Reskit/Robocopy a été installé. Attention, le
programme peut avoir été installé/copié autrement. Et, sous Vista,
Robocopy est présent d'origine :

:EOF
reg query HKCUSoftwareMicrosoftResKitRobocopy /v JobDir >null
if ERRORLEVEL 1 goto :ERR
echo Installed
goto :EOF

:ERR
cls
echo Not_installed




@+

Michel Claveau




Avatar
Gilles LAURENT [MVP]
"Azur" a écrit dans le message de
news:
| Bonjour,

Bonjour,

| Je cherche à tester en vbscript la presence d'un fichier
| (robocopy.exe) sans en connaitre sa position réelle.

--- Coupez ici : FindOnPath.vbs ---
Const FILE="robocopy.exe"
Set oSh=CreateObject("WScript.Shell")
Set oFs=CreateObject("Scripting.FileSystemObject")
arrPath=Split(oSh.ExpandEnvironmentStrings("%PATH%"),";")
For Each strPath In arrPath
If oFs.FileExists(strPath & "" & FILE) Then
WScript.Echo strPath
bFound = True
End If
Next
If Not bFound Then WScript.Quit

' le fichier est présent dans le path
' poursuite du traitement
--- Coupez ici : FindOnPath.vbs ---

En complément de la réponse de Michel, ci-dessous une version batch
alternative qui affiche le chemin complet ou se situe le fichier :

--- Coupez ici : FindOnPath.cmd ---
@echo off
set FILE="robocopy.exe"
for %%i in (%FILE%) do (
if not "%%~$PATH:i"=="" (
echo %%~dp$PATH:i
) else goto :EOF
)

rem le fichier est présent dans le path
rem poursuite du traitement
--- Coupez ici : FindOnPath.cmd ---

--
Gilles LAURENT
MVP Windows Server - Admin Frameworks
http://glsft.free.fr
Avatar
Azur
C'est super beau.

Première fois que je fois la commande "split" en
action, très interressant !

Merci


-azur-







"Gilles LAURENT [MVP]" a écrit dans le message de news:
%
"Azur" a écrit dans le message de
news:
| Bonjour,

Bonjour,

| Je cherche à tester en vbscript la presence d'un fichier
| (robocopy.exe) sans en connaitre sa position réelle.

--- Coupez ici : FindOnPath.vbs ---
Const FILE="robocopy.exe"
Set oSh=CreateObject("WScript.Shell")
Set oFs=CreateObject("Scripting.FileSystemObject")
arrPath=Split(oSh.ExpandEnvironmentStrings("%PATH%"),";")
For Each strPath In arrPath
If oFs.FileExists(strPath & "" & FILE) Then
WScript.Echo strPath
bFound = True
End If
Next
If Not bFound Then WScript.Quit

' le fichier est présent dans le path
' poursuite du traitement
--- Coupez ici : FindOnPath.vbs ---

En complément de la réponse de Michel, ci-dessous une version batch
alternative qui affiche le chemin complet ou se situe le fichier :

--- Coupez ici : FindOnPath.cmd ---
@echo off
set FILE="robocopy.exe"
for %%i in (%FILE%) do (
if not "%%~$PATH:i"=="" (
echo %%~dp$PATH:i
) else goto :EOF
)

rem le fichier est présent dans le path
rem poursuite du traitement
--- Coupez ici : FindOnPath.cmd ---

--
Gilles LAURENT
MVP Windows Server - Admin Frameworks
http://glsft.free.fr