Friday, October 5, 2012

Multiple Commands in Batch File Loop

Multi-Line loops are not allowed in WINDOWS CMD.exe. Here is how to get around it. The following code clears the contents of the directories supplied by the F1 and F2 variables. :Set folders you wish to clear: set F1=C:\JM\DeleteThisFolderContents set F2=C:\JM\DeleteThisFolderContentsAlso :Make the commands you wish to execute on the folders :COMMANDS WITH PARAMETERS MUST NOT HAVE SPACES IN THEM! set C1=RD/S/Q set C2=MD set PP=pause FOR %%A IN (%C1% %C2%) DO FOR %%B IN (%F1% %F2%) DO %%A %%B pause

No comments:

Post a Comment