0

I've got a .bat file that will apply a few quick ImageMagick conversions across a large collection of subdirectories. I need to get this script to also push the output files to AWS S3 using the S3Express utility (Windows variant of S3cmd).

echo off
set dest=destination-bucket/testfolder/
for /D %%d in (*) do (
    cd %%d
    ​​md small
    convert %1 -resize 350x350 -quality 80 -strip ./small/image.jpg
    md medium
    convert %1 -resize 640x640 -quality 80 -strip ./medium/image.jpg
    md large
    convert %1 -resize 1080x1080 -quality 30 -strip ./large/image.jpg
    md xlarge
    convert %1 -resize 1440x1440 -quality 30 -strip ./xlarge/image.jpg
    cd..
    "C:\Program Files\S3Express\S3Express.exe"
    put %%d %dest% -s -cacl:public-read -cond:"name matches 'image.jpg'"
    REM -s    == recursive (replicates subfolder structure)
    REM -cacl == canned access control list (ACL) :: Everyone gets READ access
    REM -cond == filter :: only pushes "image.jpg" files.
)

Named as "conv.bat", I would run this as "conv image.jpg".

The problem arises with "put", which is a S3Express command.

How can I get my script to plug the put command into S3Express at the end of each loop? In its current state, the script runs through the loop once, stopping after it opens 'S3Express.exe'.

It may or may not be relevant to note that this is my first batch script, and my first time using S3Express.

muad-dweeb
  • 995
  • 1
  • 9
  • 24
  • 1
    By the way, you can do `md small med large xlarge` in one shot instead of firing it up 4 times. You can also do all your IM `converts` in a single shot and save lots of time if you have many images... `convert %1 -strip \( +clone -resize 350x350 -quality 80 -write small/image.jpg \) \( +clone -resize 640x640 -quality 80 -write med/image.jpg \) ... -resize 1440x1440 -quality 30 large/image.jpg` – Mark Setchell Jan 07 '15 at 10:15
  • @MarkSetchell Hey, thanks for the 'md' one-liner, that's really cool. Regarding the ImageMagick condensation, is it more functional and/or fast to only run 'convert' once? In my eyes, it's not as readable, but if there's a performance gain I'd opt for that. – muad-dweeb Jan 08 '15 at 02:28
  • If you have a large number of images, it could make quite a difference. If just a dozen or two, go with the readable version. – Mark Setchell Jan 08 '15 at 07:37

1 Answers1

0

I'm assuming that you are trying to run S3Express.exe, and enter the put command. Like you would do normally in a command prompt. However, when you are calling S3Express.exe you are calling a new process in the same window - all following commands will not run until this process is finished.

After looking at some of the S3Express documentation, I believe you should be able to do the following - all on one line.

"C:\Program Files\S3Express\S3Express.exe" "put %%d %dest%" -s -cacl:public-read -cond:"name matches 'image.jpg'" -exit

The -exit on the end is so you are not stuck in the context of S3Express after you have run the command, and your loop should continue.

I am not sure how the quotation marks (after variable expansion) will work in the part "put %%d %dest%" - according to the documentation you need to escape quotation marks with \. You may need to replace it with something like the following "put \"%%~d\" \"%dest%\"".

unclemeat
  • 5,029
  • 5
  • 28
  • 52