Lire un fichier ligne par ligne en batch
Posté le 9 février, 2009 dans Batch, Windows | Aucun Commentaire »
Pour lire un fichier ligne par ligne dans un script batch :
for /F "eol=n delims=" %%i in (fichier.txt) do ( echo %%i )
Pour lire un fichier ligne par ligne dans un script batch :
for /F "eol=n delims=" %%i in (fichier.txt) do ( echo %%i )
Pour demander un choix dans un script batch :
@echo off :debut echo 1) choix 1 echo 2) choix 2 set /p CHOIX=Quel est votre choix ? echo Votre choix est : %CHOIX% if '%CHOIX%' == '' goto erreur rem if not '%CHOIX%' == '1' goto erreur rem if not '%CHOIX%' == '2' goto erreur goto ok :erreur echo Erreur goto debutk echo Votre choix est : %CHOIX%
Pour lancer un shell Cygwin directement dans un dossier sélectionné dans l’explorateur, remplacer le fichier Cygwin.bat par celui-ci (en considérant que l’install de Cygwin a été faite dans C:\Cygwin) :
@echo off C: chdir C:\cygwin\bin if '%1' == '' goto default bash --login -i -c "cd '%1'; exec bash" goto end :default bash --login -i :end
Ensuite, faire un raccourci de ce fichier .bat dans le dossier ‘SendTo’. Il ne reste plus qu’à envoyer n’importe quel dossier sur ce script batch.
Pour lancer une commande MS-DOS depuis un clic-droit sur un dossier dans l’explorateur, et directement dans le dossier sélectionné, exécuter le fichier reg :
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Folder\shell\ Console MS-DOS\command] @="cmd.exe"
‘Console MS-DOS’ peut être remplacé par tout autre chaîne à faire apparaître dans le menu contextuel.
Pour exporter une vidéo au format iPod en utilisant QuickTime Player :
set videoPath to /Users/jeanffy/Desktop/example.flv
set extension to (do shell script
"echo \"" & videoPath & "\" | sed 's/.*\\.//'")
set baseName to (do shell script
"basename \"" & videoPath & "\" ." & extension)
tell application "QuickTime Player"
open videoPath
stop front document
delay 5 -- pour laisser charger la video
export front document to
"/Users/jeanffy/Desktop/" & baseName & ".m4v" as iPhone
close front document
end tell
Voici comment créer un fichier texte rapidement dans le dossier actuellement sélectionné dans le Finder :
tell application "Finder"
set pwdAlias to insertion location as alias
if not (exists folder pwdAlias) then
set pwdAlias to (container of pwdAlias) as alias
end if
set pwd to POSIX path of pwdAlias
do shell script "touch \"" & pwd & "/Nouveau.txt\""
end tell
Placer ce script dans le dossier /Users/%USER%/Library/Scripts pour pouvoir l’utiliser depuis la barre de menu du Finder.
Voici un script AppleScript qui permet de réaliser rapidement un ISO à partir d’un dossier du disque dur ou bien du lecteur de CD :
set inputFolder to choose folder with prompt "Sélectionner le dossier source:" without invisibles set inputPath to (POSIX path of inputFolder) set baseName to do shell script "basename "" & inputPath & """ set desktopPath to the path to the desktop folder set outputISO to choose file name with prompt "Sélectionner le fichier ISO à créer:" default name baseName & ".iso" default location desktopPath without invisibles set outputPath to (POSIX path of outputISO) set cmd to "hdiutil makehybrid -o "" & outputPath & "" -udf -iso -joliet "" & inputPath & """ do shell script cmd
A la fin d’un script AppleScript, il peut est utile de jouer un son :
do shell script "afplay /System/Library/Sounds/Glass.aiff"
ou d’afficher une notification growl :
do shell script "growlnotify -a "/Applications/AppleScript/Script Editor.app" -s -m "Script terminé.""
Voici un petit script AppleScript qui permet de boucler sur les fichiers actuellement sélectionnés dans la fenêtre courante du Finder :
tell application "Finder"
set selectedFiles to selection
repeat with oneFile in selectedFiles
-- posixPath = chemin du fichier avec des /
-- macPath = chemin du fichier avec des :
set posixPath to (POSIX path of (oneFile as alias))
set macPath to (oneFile as alias)
log posixPath
log macPath
end repeat
end tell
Au milieu du HTML écrire :
<?='du texte'?>
Ceci est l’équivalent de :
<?php echo 'du texte'; ?>