• Blog
  • Info Support
  • Career
  • Training
  • International Group
  • Info Support
  • Blog
  • Career
  • Training
  • International Group
  • Search
logo InfoSupport
  • Latest blogs
  • Popular blogs
  • Experts
      • Alles
      • Bloggers
      • Speakers
  • Meet us
  • About us
    • nl
    • en
    • .NET
    • Advanced Analytics
    • Agile
    • Akka
    • Alexa
    • Algorithms
    • Api's
    • Architectuur
    • Artificial Intelligence
    • ATDD
    • Augmented Reality
    • AWS
    • Azure
    • Big Data
    • Blockchain
    • Business Intelligence
    • Cloud
    • Code Combat
    • Cognitive Services
    • Communicatie
    • Containers
    • Continuous Delivery
    • CQRS
    • Cyber Security
    • Dapr
    • Data
    • Data & Analystics
    • Data Science
    • Data Warehousing
    • Databricks
    • DevOps
    • Digital Days
    • Docker
    • eHealth
    • Enterprise Architecture
    • Hacking
    • Infrastructure & Hosting
    • Innovatie
    • Integration
    • Internet of Things
    • Java
    • Machine Learning
    • Microservices
    • Microsoft
    • Microsoft Bot Framework
    • Microsoft Data Platform
    • Mobile Development
    • Mutation Testing
    • Open source
    • Pepper
    • Power BI
    • Privacy & Ethiek
    • Python
    • Quality Assistance & Test
    • Quality Assurance & Test
    • Requirements Management
    • Scala
    • Scratch
    • Security
    • SharePoint
    • Software Architecture
    • Software development
    • Software Factory
    • SQL Server
    • SSL
    • Start-up
    • Startup thinking
    • Stryker
    • Test Quality
    • Testing
    • TLS
    • TypeScript
    • Various
    • Web Development
    • Web-scale IT
    • Xamarin
    • Alles
    • Bloggers
    • Speakers
Home » Renaming photographs from your digital camera
  • Renaming photographs from your digital camera

    • By Oud-medewerkers
    • Various 14 years ago
    • Various 0 comments
    • Various Various
    Renaming photographs from your digital camera

    I bought my first digital camera a few years back, and used the setting to create sequenced numbering of the files in the format PICTxxxx, where xxxx would increment regardless of the date. At the time I was using the following directory structure:

    DCIM
     2006
      200609
       20060919
        PICT9974.jpg
        PICT9975.jpg 

    After about two years the counter had reached 9999 and reset itself to 0000. I decided soon after to set the camera to reset the counter on each new day, which was not a problem as a new folder was created for each day. Now I had the following situation:

    DCIM
     2007
      200704
       20070407
        PICT0001.jpg
        PICT0002.jpg
       20070408
        PICT0001.jpg
        PICT0002.jpg 

    When putting together albums and CD's I now faced a photo identifying dilemma: how could I uniquely refer to a picture in my collection? If I wanted to put the pictures from both 20070407 and 20070408 together I would need to rename them upon copying, and this wasn't always desired.

    I wanted a way to name and find each file by its unique name, not by using paths and so forth. I decided that I wanted the files to have the following naming convention:
                GG-yyyyMMdd-xxxx.*
    where GG are my initials, yyyyMMdd the day the picture was taken, and xxxx was the day counter. Using this convention I could shoot 10.000 pictures a day before needing to take further action to uniquely identify the files.

    I considered writing a VBScript to do this, but couldn't think of how to do it exactly. The renaming would have to be done based on the file's LastWriteTime property, as some of the parent directories weren't reliable sources for the yyyyMMdd part of the filename. I had sometimes added extra directories under the day level, to separate periods during a day-long wedding shoot for instance. The xxxx part could not be random or generated but had to be the same as the file originally had.

    I then turned to PowerShell, and after a bit of testing, I had come up with the following one-liner to get my files that were to be renamed listed and tested:

    Get-ChildItem -include pict*.* -Recurse |
    >> 
    foreach-object { $_.directoryname + "" + $_.name +
    >>  " = "+ ($_.Name -replace "pict",
    >> ("GG-"+$_.lastwritetime.toString('yyyyMMdd')+"-"))}
     

    The first part (up to the | pipe sign) gets all files matching the pattern pict*.* in all underlying directories as objects, with all their properties, attributes and methods available for use in the second part. The second part takes each object, lists the path (including the current filename) where it was found, and shows how the new name will look like.
    Here I used the LastWriteTime property of my files, as I always have either my photo organizer ThumbsPlus or the exiffile tool from the EXIFUtils toolkit set the file modified time to the EXIF Date & Time Taken value from the picture.
    This way I can edit or rotate a picture and still keep the Modified date & time correct to the actual date and time the picture was taken. I then used the toString method of the LastWriteTime property to extract / format only the date in a yyyyMMdd format, ie. 20070407.
    By replacing the "pict" with "GG-20070407-" I now had GG-20070407-0001.jpg as the new filename, just as I wanted.

    To ease my checking of the list I altered it to output the list as a CSV file:
    Get-ChildItem -include pict*.* -Recurse |
    >>  foreach-object { $_.directoryname + "" + $_.name +
    >>  ","+ ($_.Name -replace "pict",
    >> ("GG-"+$_.lastwritetime.toString('yyyyMMdd')+"-"))} > allfiles2Brenamed.csv
     

    Thorough checking revealed that some pictures had the wrong date. How was this happening? Apparently the pictures had been taken close to the midnight hour, and had a different timestamp than I expected. This was due to either the camera or the system where I first transferred the files from the card to a PC marking not only the time, but also the UTC time. With the recent change to regular (non-DST) time, the date-time properties were being adjusted on the fly by the system, and the pictures were being show to be an hour earlier on the previous day. This was only a problem with a few pictures, and once I had identified them I could easily fix them afterwards. In the future I'll have a think about how I want to fix this so my pictures / renaming code will not be affected by the timezone I happen to be in.

    Now that I was satisfied that all my own photographs were included in the selection list it was time for the actual rename. I rewrote the command to include the Rename-Item cmdlet as follows:

    Get-ChildItem -include pict*.* -Recurse |
    >>  foreach-object { rename-item $_ -newname ($_.Name -replace "pict",
    >> ("GG-"+$_.lastwritetime.toString('yyyyMMdd')+"-"))}
     

    I first tested it on a copy of a subdirectory just to be sure, and it all worked perfectly! I then proceeded to the root of my photo hierarchy, DCIM, and ran the command again. Within mere seconds, all of my photographs were renamed, including RAW and TIFF versions I had of some of them.
    To use these scripts with a different camera all that's needed is to identify the common part, like PICT in this case, or DSC or DCS in others. Instead of keeping the sequential number the actual date and time could also be used as follows:

    Get-ChildItem -include pict*.* -Recurse |
    >>  foreach-object { rename-item $_ -newname
    >> ("GG-"+$_.lastwritetime.toString('yyyyMMdd-hhmmss')}

    Now all I had to do was update the ThumbsPlus SQL database to reflect these changes prior to starting the program up, so that it would not see the files as new ones and the data in the database as belonging to orphaned (removed from the filesystem but still in the database) thumbnails and decide to clean the database up. This way all my custom userdata, galleries, and tracking info would remain intact. A few test runs and SQL scripts later I had it done and started ThumbsPlus up, and got the expected and desired results.

    Thanks PowerShell!

     

    P.S.: My camera also has the tendency to name the folders it creates by using a combination of a sequential number and the date, in the following way:

    DCIM
       10170407
        PICT0001.jpg
        PICT0002.jpg
       10270408
        PICT0001.jpg
        PICT0002.jpg 

    Here the first 3 numbers of the directories are sequential, and the last 5 are yMMdd. When copying to my photorepository on my PC I like to have them renamed to yyyyMMdd instead of ###yMMdd, so I used to do that manually. I now also have a PowerShell script to do this for me:

    Get-Childitem |
    >>  where {($_.attributes -like "dir*") -and ($_.name -notlike "100KM*")} |
    >>  foreach-object { rename-item $_ -newname $_.lastwritetime.toString('yyyyMMdd')}

    The Where operator allows me to only rename directories that aren't the 100KM* settings directory. Other cameras use a different name for their settings directory, so this can be changed if needed. I could have just replaced the first 3 characters with 200 instead of using the datestamp, but in about 3 years this would not work anymore, and I'm not going make the Y2K assumptions and errors all over again 😉

    Share this

Oud-medewerkers

View profile

IT Training at Info Support

Which training fits you?

Consultancy

Consultancy

Related blogs

  • Video Conferencing en OBS Studio koppelen: online prese…

    Video Conferencing en OBS Studio koppelen: online prese… Maaike Brouwer - 1 year ago

  • Verantwoordelijkheid pakken in jouw eigen persoonlijke …

    Verantwoordelijkheid pakken in jouw eigen persoonlijke … Stephan Versteegh - 1 year ago

  • Tips voor als je gaat afstuderen

    Tips voor als je gaat afstuderen Bart Renders - 2 years ago

Related downloads

  • Beslisboom voor een rechtmatig ‘kopietje productie’

  • Klantreferentie: Remmicom zet wetgeving om in intellige…

  • Klantreferentie RDW: Samenwerken voor veilig en vertrou…

  • Klantreferentie BeFrank: Strategische IT voor een innov…

  • Wie durft te experimenteren met data in de zorg?

Related videos

  • mijnverzekeringenopeenrij.nl

    mijnverzekeringenopeenrij.nl

  • Winnaar | Innovation Projects 2017

    Winnaar | Innovation Projects 2017

  • Explore | Info Support & HAN & Poliskluis

    Explore | Info Support & HAN & Poliskluis

  • LifeApps bij HagaZiekenhuis

    LifeApps bij HagaZiekenhuis

  • Info Support | Bedrijfsfilm

    Info Support | Bedrijfsfilm

Nieuwsbrief

* verplichte velden

Contact

  • Head office NL
  • Kruisboog 42
  • 3905 TG Veenendaal
  • T +31 318 552020
  • Call
  • Mail
  • Directions
  • Head office BE
  • Generaal De Wittelaan 17
  • bus 30 2800 Mechelen
  • T +32 15 286370
  • Call
  • Mail
  • Directions

Follow us

  • Twitter
  • Facebook
  • Linkedin
  • Youtube

Newsletter

Sign in

Extra

  • Media Library
  • Disclaimer
  • Algemene voorwaarden
  • ISHBS Webmail
  • Extranet
Beheer cookie toestemming
Deze website maakt gebruik van Functionele en Analytische cookies voor website optimalisatie en statistieken.
Functioneel
Altijd actief
De technische opslag of toegang is strikt noodzakelijk voor het legitieme doel het gebruik mogelijk te maken van een specifieke dienst waarom de abonnee of gebruiker uitdrukkelijk heeft gevraagd, of met als enig doel de uitvoering van de transmissie van een communicatie over een elektronisch communicatienetwerk.
Voorkeuren
De technische opslag of toegang is noodzakelijk voor het legitieme doel voorkeuren op te slaan die niet door de abonnee of gebruiker zijn aangevraagd.
Statistieken
De technische opslag of toegang die uitsluitend voor statistische doeleinden wordt gebruikt. De technische opslag of toegang die uitsluitend wordt gebruikt voor anonieme statistische doeleinden. Zonder dagvaarding, vrijwillige naleving door uw Internet Service Provider, of aanvullende gegevens van een derde partij, kan informatie die alleen voor dit doel wordt opgeslagen of opgehaald gewoonlijk niet worden gebruikt om je te identificeren.
Marketing
De technische opslag of toegang is nodig om gebruikersprofielen op te stellen voor het verzenden van reclame, of om de gebruiker op een website of over verschillende websites te volgen voor soortgelijke marketingdoeleinden.
Beheer opties Beheer diensten Beheer leveranciers Lees meer over deze doeleinden
Voorkeuren
{title} {title} {title}