Here’s another cool for loop example:

Create an “alphabet.txt” file containing all the letters in the alphabet beginning with d.

d
e
f
g
,etc, etc, etc

for /f %%i in (alphabet.txt) do if exist %%i:\USMT\*.* xcopy %%i:\USMT\*.* /e /v /y C:\Windows\USMT\

I picked this up from a Windows 7 document M$ posted about the “User State Migration Tool”.  In the document found > here < they give an example for you to run the USMT from a pen drive.  They had this command set.

If exist D:\USMT\*.* xcopy D:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist E:\USMT\*.* xcopy E:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist F:\USMT\*.* xcopy F:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist G:\USMT\*.* xcopy G:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist H:\USMT\*.* xcopy H:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist I:\USMT\*.* xcopy I:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist J:\USMT\*.* xcopy J:\USMT\*.* /e /v /y C:\Windows\USMT\
If exist K:\USMT\*.* xcopy K:\USMT\*.* /e /v /y C:\Windows\USMT\

This is pretty trivial (I know) but it certainly cleans up the batch file should I decide to add more information in it or if I add this to a larger set of tools, maybe a utility menu where this is merely just an option for other technitians to use.  Should I need to add more than just a “copy data from my pen drive to my hard drive” in the future I could easily do so and it’s a great reference for people looking for for loop examples.  For more for loop examples click > here <

Most of the stuff I post here are technical notes turned blogs so we can all bennefit!