Media Sync: Organize Your Photos and Videos with PowerShell

Do you have photos and videos that you have taken over the years that are scattered all over the place? Do you want to have all your photos and videos organized? Do you want all your photos and videos to have a standardized naming scheme? If you answered YES to these questions, then this is the post for you. In this post, I will provide you with the PowerShell code and examples for how to use the Media Sync script. The Media Sync script utilizes the Shell.Application COM object to gather file metadata. Only files that have a picture or video metadata type will be processed. The script uses the date taken for pictures and the media created metadata fields to organize the photos and videos. If there is no date taken or media created available for a given file, the script will use the modify date instead. The script also ensures that you won’t have any duplicate files by checking the file hashes of the two files in question. If the script detects duplicate files, it will only keep one copy of the file. There are also tools included to help you cleanup unwanted files or folders, delete empty directories and find duplicate files. The script has a simple menu driven PowerShell GUI similar to what I did in a previous post. The Media Sync PowerShell script provides the following features:

  • COPY all photos and videos in a given folder structure (maintains original file in original location).
  • MOVE all photos and videos in a given folder structure (original file is renamed and moved).
  • Rename the photo or video based on the date the photo or video was taken.
  • Directory structure organized by year and month the photo or video was taken.
  • Ability to delete any empty folders in a given path, this will help with the cleanup process after you have moved photos and videos from the original location.
  • Remove all files based off a given file extension, this will help with the cleanup process after you have moved photos and videos from the original location.
  • Utilize Out-GridView to highlight and delete files or folders, this can be used to cleanup files of any file extension.
  • Find duplicate files in a given directory.
  • View files in a given directory via Out-GridView.

How to Use

DISCLAIMER: Use at your own risk. The script is safe but has the ability to delete files and folders so just be careful.

In the below video examples, I use PowerShell 7.1 with the Windows Terminal. There are no additional prerequisites that need to be met to run this script. I recommend that you setup a temporary test folder structure like I have in the video examples before running this script against all of your photos and videos. Much of the data is outputted via Out-GridView. If you want to select all the items in Out-GridView, you can use CTRL + A to select all. The code is located in my GitHub, please click on the below link to access it.

GitHub


1: COPY files and folders

The first item in the Media Sync script that we are going to look at is the COPY process. This process should be used if you want to maintain the original file and folder structure. The source directory will NOT be modified at all during this process. This results in the same outcome that would occur if you manually copied and pasted the files from the source to the destination directory. In the below video example, I show you the steps to take and the expected output when you choose 1 for the COPY process.


2: MOVE files and folders

The second item in the Media Sync script that we are going to look at is the MOVE process. This process should be used if you want to rename and move the original file. The source directory WILL be modified during this process. This results in the same outcome that would occur if you manually cut and pasted the files from the source to the destination directory. In the below video example, I show you the steps to take and the expected output when you choose 2 for the MOVE process.


3: CLEANUP files and folders

The third item in the Media Sync script that we are going to look at is the CLEANUP process. This process should be used if you need to cleanup files or folders after you conduct a MOVE process. After you conduct a MOVE process, you will most likely be left with unwanted files and folders. Utilizing one of the below options could help you in that cleanup process.

3:1 Remove files with given extension (manual input)

In the below video example, I show you the steps to take and the expected output when you choose 3:1 for the CLEANUP process to remove files with a given extension. In the example, I inputted the file extension of txt but you can use any file extension that you want to remove.

3:2 Delete all empty directories

In the below video example, I show you the steps to take and the expected output when you choose 3:2 for the CLEANUP process to delete all empty directories. The Out-GridView results will display all empty directories. If there are no empty directories then there will be no Out-GridView displayed.

3:3 Utilize Out-GridView to highlight and delete files or folders

In the below video example, I show you the steps to take and the expected output when you choose 3:3 for the CLEANUP process to utilize Out-GridView to highlight and delete files or folders.

3:4:1 Find duplicate files in a given directory (View all of the duplicate files detected)

Use this process to view the duplicate files before you take action on them. Think of this as a report of the duplicate files detected. If two files are identical, then they will have the same exact hash. The Out-GridView results will display the hash for the files detected as duplicates.

3:4:2 Find duplicate files in a given directory (Move files for ONE duplicate group at a time)

Use this process if you want to view the duplicate groups one at a time instead of all of the duplicate groups at once. If you have a large amount of duplicates this can be cumbersome to click through, but you may prefer it for smaller batches of files. If two files are identical, then they will have the same exact hash. The Out-GridView results will display the hash for the files detected as duplicates so that you can decide which files to move to the duplicates directory.

3:4:3 Find duplicate files in a given directory (Move files for ALL duplicate groups)

In the below video example, I show you the steps to take and the expected output when you choose 3:4:3 for the CLEANUP process to find duplicate files in a given directory by moving files for ALL duplicate groups at once. If two files are identical, then they will have the same exact hash. The Out-GridView results will display the hash for the files detected as duplicates so that you can decide which files to move to the duplicates directory. In the video example below, I select one file per hash group to be moved.

3:4:4 Find duplicate files in a given directory (Auto move files)

Use this process if you do not want to utilize Out-GridView to review the duplicate results and just want to auto move duplicate file(s) to the duplicates directory. This process is the fastest, but you have less control over the results because the script will auto select which files get moved to the duplicates directory. For example, if you have 3 files that are identical, then the script will move 2 of those files to the given duplicates directory and keep 1 in the original location.

3:5 View files in a directory

In the below video example, I show you the steps to take and the expected output when you choose 3:5 for the CLEANUP process to view files in a directory. Use this process if you simply want to view all the files and folders in a given directory. This process is just for reporting purposes.

That’s it for now, thanks for reading!


Check out my other blog posts:

One thought on “Media Sync: Organize Your Photos and Videos with PowerShell

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s