@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set LOOP=100
set RARPATH="C:\Program Files\WinRAR\rar.exe"

rem ************************************************
rem * Clean Directories and files from previous runs
rem ************************************************

del MyCommandFile.cmd, AllStoredFiles.rar
rmdir /S /Q .\MyGeneratedFiles
rmdir /S /Q .\MyCompressedFiles
mkdir MyGeneratedFiles
mkdir MyCompressedFiles


rem *******************************************************************
rem * Generate Sample files with fsutil which will later be archived.
rem *
rem * This part of the sample depicts how to submit a single command with  
rem * xgsubmit. In this case  it is called many times in a loop.
rem * The command that is submited for local execution here is
rem *
rem * 	"fsutil file createnew .\MyGeneratedFiles\%%E.txt 1048576"
rem *******************************************************************

for /L %%E in (1,1,%LOOP%) do ( 
	xgsubmit /group=generation /allowremote=off /caption="Generating %%E.txt" /command fsutil file createnew .\MyGeneratedFiles\%%E.txt 1048576
)

rem *************************************************
rem * Wait for all the compression tasks to finish 
rem *************************************************

xgwait /group=generation

rem ************************************************************
rem * Generate a command file with the commands to be submited
rem * for remote execution (using maximum WinRar compression method)
rem ************************************************************

for /L %%E in (1,1,%LOOP%) do ( 
	echo   %RARPATH%  a  MyCompressedFiles\%%E.rar  .\MyGeneratedFiles\%%E.txt -ep1 -m5 >> MyCommandFile.cmd
)


rem *******************************************************
rem * Submit the files to be compressed on the Grid
rem * Using a command file we prepeared in the step above.
rem *******************************************************

xgsubmit /group=compression /allowremote=on /commandfile MyCommandFile.cmd


rem *************************************************
rem * Wait for all the compression tasks to finish 
rem *************************************************

xgwait /group=compression


rem *************************************************
rem * Store all the compressed files into one archive 
rem * file (using the WinRar "store" compression level)
rem *************************************************

xgsubmit /allowremote=off /caption="Store All files" /command  %RARPATH%  a AllStoredFiles.rar  MyCompressedFiles\*.* -ep1 -m0
