anchor.diff:      SET good=true
       IF "!arg!"=="" SET good=false
       IF "!arg:~0,1!"=="-" SET good=false
  -    IF !good!==true (SHIFT) ELSE (ECHO Error: --profile requires an argument 1>&2 & EXIT /B 2)
  +    IF !good!==true (SHIFT) ELSE (ECHO Error: --profile requires an argument >> "%ERROR_FILE%" & EXIT /B 1)
       SET profile=!arg!
       SHIFT
       GOTO loop
  
positive.code: ECHO    Bucket: %bucket%
  ECHO    Key: %key%
  IF NOT "%options%"=="" ECHO    Options: %options%
  SET RESPONSE_FILE=response.txt
  SET ERROR_FILE=error.txt
  aws s3api create-multipart-upload --bucket %bucket% --key %key% %options% --profile %profile%> "%RESPONSE_FILE%" 2> "%ERROR_FILE%"
  
  :: Rethrow any error messages from the AWS API
  FOR /F %%i IN ("%ERROR_FILE%") DO SET size=%%~zi
  IF %size% GTR 0 (
      ECHO Creation failed with error message: 1>&2
      TYPE "%ERROR_FILE%" 1>&2
      DEL "%ERROR_FILE%"
      EXIT /B 1
  )
  DEL "%ERROR_FILE%"
  
  :: Store the new upload ID
  :: Remove double quotes, spaces, commas, and leading text from AWS response
  SET ID_FILE=upload-id.txt
  FINDSTR /C:"UploadId" "%RESPONSE_FILE%"> "%ID_FILE%"
  DEL "%RESPONSE_FILE%"
  SET /P uploadID= < "%ID_FILE%"
  DEL "%ID_FILE%"
  SET uploadID=%uploadID:"=%
  SET uploadID=%uploadID: =%
  SET uploadID=%uploadID:,=%
  SET uploadID=%uploadID:*:=%
  ECHO Creation succeeded with upload-id:
  ECHO    %uploadID%
  
  :: Unset local vars before exit
  SET RESPONSE_FILE=
  SET ERROR_FILE=
  SET ID_FILE=
  SET size=
  
  EXIT /B 0
  
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  :: void uploadParts(string filedir)
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  :uploadParts
  
  SETLOCAL EnableDelayedExpansion
  
  :: Count the number of file parts in the provided directory
  SET numFiles=0
  FOR %%F IN ("%filedir%\*.*.*") DO SET /A numFiles+=1
  
  :: Add initial lines to parts JSON file
  ECHO.
  
negative.code:     ECHO }
  )
  
  
  EXIT /B %numErrs%
  
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  :: int completeMultipartUpload()
  ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  :completeMultipartUpload
  
  SETLOCAL EnableDelayedExpansion
  
  SET completeErrFile=completeErr.txt
  
  :: Create the AWS S3 multipart upload (can't pass null string to --metadata argument)
  SET filedir=%filedir:"=%
  ECHO.
  ECHO Completing the multipart upload to %key% in bucket %bucket%...
  aws s3api complete-multipart-upload --bucket %bucket% --key %key% --profile %profile% --multipart-upload file://"%ETAGS_JSON%" --upload-id %uploadID%> "%RESPONSE_FILE%" 2> "%completeErrFile%"
  
  :: Rethrow any error messages from the AWS API
  FOR /F %%i IN ("%completeErrFile%") DO SET size=%%~zi
  IF %size% GTR 0 (
      ECHO Completion failed with error message: >> "%ERROR_FILE%"
      TYPE "%completeErrFile%" >> "%ERROR_FILE%"
      DEL "%completeErrFile%"
      EXIT /B 1
  )
  DEL "%completeErrFile%"
  
  :: Store the new upload ID
  :: Remove double quotes, spaces, commas, and leading text from AWS response
  SET LOC_FILE=s3loc.txt
  FINDSTR /C:"Location" "%RESPONSE_FILE%"> "%LOC_FILE%"
  SET /P s3loc= < "%LOC_FILE%"
  DEL "%LOC_FILE%"
  SET s3loc=%s3loc:"=%
  SET s3loc=%s3loc: =%
  SET s3loc=%s3loc:,=%
  SET s3loc=%s3loc:*:=%
  ECHO Completion succeeded!  Your object is now stored in S3 at:
  ECHO     %s3loc%
  
  EXIT /B 0
  