windows - Batch to loop through all files with predefined list or set of extensions and ignore all other file types -
i have following windows-batch script loop through files in current directory:
for %%f in (%cd%\*.*) ( :: doing process here )
i know can loop through specific file type using *.ext
, need loop through given below file types , ignore other types, in single for
loop only:
php phtml css js sql xml
how can achieve doing slightest modifications code possible ?
i not of batch-scripter, appreciated.
what using command line in batch file?
for %%i in (*.php *.phtml *.css *.js *.sql *.xml) echo "%%i"
or perhaps better depending on want do:
for /f "delims=" %%i in ('dir /a-d /b *.php *.phtml *.css *.js *.sql *.xml 2^>nul') echo "%%i"
the version dir works files hidden attribute set , better when files in current directory renamed, moved or deleted, i.e. current directory files list changes due commands in body of for loop because of list of files processed for not change once dir command executed not case on using first solution. first solution can result in unexpected behavior double processing file, skipping unexpected files or endless running loop when files renamed, moved, modified or deleted in current directory.
run in command prompt window for /?
, dir /?
on 2 commands support both specifying multiple wildcard patterns on arguments list.
Comments
Post a Comment