Code: Select all
@ECHO OFF
SET P1=C:\WINDOWS\NOTEPAD.EXE
SET P2=C:\Programs\IrfanView\i_view32.exe
SetLocal EnableExtensions EnableDelayedExpansion
FOR /F %%V IN ('ECHO %1 ^|FIND /I /C ".BAT"') DO (SET K1=%%V
IF !K1!==1 (EndLocal& %P1% %1 ) & (GOTO :EOF)
)
FOR /F %%V IN ('ECHO %1 ^|FIND /I /C ".TXT"') DO (SET K1=%%V
IF !K1!==1 ( EndLocal& %P1% %1 ) & (GOTO :EOF)
)
FOR /F %%V IN ('ECHO %1 ^|FIND /I /C ".TRU"') DO (SET K1=%%V
IF !K1!==1 ( EndLocal& %P1% %1 ) & (GOTO :EOF)
)
FOR /F %%V IN ('ECHO %1 ^|FIND /I /C ".BMP"') DO (SET K1=%%V
IF !K1!==1 ( EndLocal& %P2% %1 ) & (GOTO :EOF)
)
FOR /F %%V IN ('ECHO %1 ^|FIND /I /C ".JPG"') DO (SET K1=%%V
IF !K1!==1 ( EndLocal& %P2% %1 ) & (GOTO :EOF)
)
* what is the fastest running batch for AA.BAT? because | Find, pipe and Find command are known to run too slow.
* or conversly speaking, what is the fastest running batch for a case like this?
if the file extensions are one of the followings , then abort and take no action go to :EOF
because AA.BAT was originally meant for a text editor, but its shell opens anything and sometimes causes a PC freeze. so i figured it out by replacing it with BAT and it only passes %1, one variable. which is a full file path name.
SET Fext=*.EXE *.BMP *.MP4 *.AVI *.MP3
batch must handle filenames with "!"'s in them