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

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -