' --------------------------------------------------------------- ' Script d'ouverture d'un dossier ou fichier d'un lecteur amovible ' sans connaitre sa lettre ' ' Syntaxes : ' ' runremovable ' affiche la liste des lecteurs amovibles disponibles ' runremovable ' ouvre l'explorateur sur ce dossier ' runremovable ' ouvre ou exécute le fichier spécifié ' Si ce n'est pas un exécutable, son extension doit ' être associée à une application quelconque. ' ' JC BELLAMY © 2008 ' --------------------------------------------- Dim shell, args, fso, collDisk, disk, cd(),ready(),name(),cdok(),typeobj(),numcd() Set shell = WScript.CreateObject("WScript.Shell") Set args = Wscript.Arguments Set fso = WScript.CreateObject("Scripting.FileSystemObject") Const AMOVIBLE=1 Const SW_SHOWNORMAL=1 command="" nparam=args.Count if nparam>0 then For i = 0 To nparam-1 If i>0 Then command=" " & command command=command & args(i) Next end if ' Collection des disques. On cherche lessupports amovibles (type = 1) Set collDisk = fso.Drives nbcd=0 For each disk in collDisk If disk.DriveType=AMOVIBLE Then nbcd=nbcd+1 redim preserve cd(nbcd),ready(nbcd),name(nbcd) cd(nbcd-1)=disk.DriveLetter & ":" ready(nbcd-1)=disk.IsReady If ready(nbcd-1) Then name(nbcd-1)=disk.VolumeName else name(nbcd-1)="" end if next If len(command)=0 Then s=nbcd & " disques amovibles sur cette machine :" & VBCRLF For i = 0 To nbcd-1 If ready(i) Then state=name(i) else state="(non prêt)" s=s & cd(i) & chr(9) & state & VBCRLF Next wscript.echo s wscript.quit End If If left(command,1) <> "\" Then command="\" & command ncdok=0 For i = 0 To nbcd-1 If ready(i) Then filename=cd(i) & command if fso.FolderExists(filename) then addobjet i,filename,1 ' Dossier trouvé if fso.FileExists(filename) then addobjet i,filename,2 ' Fichier trouvé End If Next Select Case ncdok Case 0 wscript.echo "Fichier ou dossier trouvé nulle part" Case 1 Exec(0) Case else Prompt=ncdok & " fichiers ou dossiers ont été trouvés :" & VBCRLF For j= 0 To ncdok-1 Prompt=Prompt & j+1 & " : " & cdok(j) & " (" & name(numcd(j)) & ")" & VBCRLF Next Prompt=Prompt & VBCRLF & "Indiquez le n° de l'élément à ouvrir (1 à " & ncdok & ") :" & VBCRLF i=InputBox(prompt, "Ouverture de " & command,1) If i="" Then wscript.quit i=cint(i) If i<1 or i>ncdok Then wscript.quit Exec(i-1) End Select wscript.quit ' ------------------------------------- Sub addobjet(i,f,t) ncdok=ncdok+1 redim preserve cdok(ncdok),typeobj(ncdok),numcd(ncdok) typeobj(ncdok-1)=t cdok(ncdok-1)=f numcd(ncdok-1)=i End Sub ' ------------------------------------- Sub Exec(i) If typeobj(i)=1 Then cmd="Explorer /e,/select,""" & cdok(i) & """" else cmd="""" & cdok(i) & """" shell.run cmd,SW_SHOWNORMAL End Sub ' -------------------------------------