@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set LOOP=100
set GZPATH="C:\Program Files (x86)\GnuWin32\bin\gzip.exe"

rem ************************************************
rem * Clean Directories and files from previous runs
rem ************************************************

del MyCommandFile.cmd
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
copy .\MyGeneratedFiles\*.txt .\MyCompressedFiles

rem ************************************************************
rem * Generate a command file with the commands to be submited
rem * for remote execution (using maximum 7Z compression method)
rem ************************************************************

for /L %%E in (1,1,%LOOP%) do ( 
	echo   %GZPATH%  -9  MyCompressedFiles\%%E.txt   >> 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
