element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • Experts & Guidance
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • Product Groups
  • Store
    Store
    • Visit Your Store
    • 'Choose another store...'
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
STEM Academy
  • Learn
  • Learning Center
  • STEM Academy
  • More
  • Cancel
STEM Academy
Forum Help with finding and looping through folders by date.
  • Blog
  • Forum
  • Documents
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
STEM Academy requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 0 replies
  • Subscribers 38 subscribers
  • Views 296 views
  • Users 0 members are here
  • loops
  • raspberry-pi
  • bash
  • for
  • imagemagick
  • script
  • stem space
Related

Help with finding and looping through folders by date.

mikedavis
mikedavis over 7 years ago

I have a bash script that I am using for a photography project that I have been working on.  In short, I have a Raspberry Pi camera taking pictures of a sunrise everyday.  It takes those pictures and compresses them into a movie and uploads it to my Dropbox account.  Then I have another Raspberry Pi at home that downloads the movies, and turns them back into still pictures.  I am using the program Image Magick to make a montage of those pictures so they layout in a nice grid.  It should be pretty beautiful when its done.

 

The problem is that my bash script is pretty inefficient, and it requires a lot of work to prepare it.  My limited programming knowledge is an obstacle here.  My script is posted below.

 

The photos are in folders labeled by date (YYYYMMDD) and the photos themselves are labeled by date and sequenced (YYYYMMDD-0001.jpg, YYYYMMDD-0002.jpg, etc).  There are 1440 pictures in each folder. 

 

I have a for loop that goes through each folder that I identify as a variable.  I would prefer to have a for loop that finds every folder in a range of dates (20151001 - 20161001).  Is there a more efficient way to write this?  I have poked around for something, but I haven't had a lot of luck.

 

Any help would be greatly appreciated!

 

DA="20151001/20151001-";
DB="20151002/20151002-";
DC="20151003/20151003-";
DD="20151004/20151004-";
DE="20151005/20151005-";
DF="20151006/20151006-";
DG="20151007/20151007-";
DH="20151008/20151008-";
DI="20151009/20151009-";
DJ="20151010/20151010-";
DK="20151011/20151011-";
DL="20151012/20151012-";
DM="20151013/20151013-";
DN="20151014/20151014-";
DO="20151015/20151015-";
DP="20151016/20151016-";
DQ="20151017/20151017-";
DR="20151018/20151018-";
DS="20151019/20151019-";
DT="20151020/20151020-";

# for four digit numbers with leading zeroes, counter needs to start as five di$
# then remove the left most digit.
counter=10000

        for f in ${DA}*.jpg; do
                let "counter+=1"
               

                #Image Magick Montage lays the pictures out in a 10X2 grid.
                montage -tile 10x2 -geometry +1+1 ${DA}${counter:1}.jpg ${DB}${counter:1}.jpg ${DC}${counter:1}.jpg ${DD}${counter:1}.jpg ${DE}${counter:1}.jpg ${DF}${counter:1}.jpg ${DG}${counter:1}.jpg ${DH}${counter:1}.jpg ${DI}${counter:1}.jpg ${DJ}${counter:1}.jpg ${DK}${counter:1}.jpg ${DL}${counter:1}.jpg ${DM}${counter:1}.jpg ${DN}${counter:1}.jpg ${DO}${counter:1}.jpg ${DP}${counter:1}.jpg ${DQ}${counter:1}.jpg ${DR}${counter:1}.jpg ${DS}${counter:1}.jpg ${DT}${counter:1}.jpg /media/KINGSTON/montage${counter:1}.jpg
                done

  • Sign in to reply
  • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2023 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube