Backup Phone Pictures and Videos

The carrier (Verizon, Google Fi etc) that a lot of folks use for their smartphones, automatically backs up their photos and videos. Other phones and carriers do not have this feature.  It is a pretty simple process.  This is one of many links that show how to do it:

I am helping a very kind (and smart) gentleman extend a program he wrote which automatically does this. Without going into all the boring technical details, I will just say, when you connect your phone to your PC, it’s a little different than connecting USB sticks etc..  Research MTP aka Media Transport Protocol, the etc. for the boring details.

Anyone use a phone that does not automatically backup your photos and videos? Anyone want the capability to do their own backups of these files? It is really simple to do, but, I am looking at a way to do it automatically, by year, or by year and month. If this is an issue for anyone, or anyone you know, please let me know. One scenario is to find a helpful friend with a PC, then ask to plug your phone into their computer — they would only need to push a button to backup all your photos and videos to a USB stick.

Stay tuned to this page for further developments.

The General Flow of Using This Approach

In order to use the program, you will have to do this:

Connect your device by USB cable to a Windows PC.
(Bluetooth or WiFi connectivity is not under consideration at this time.)

Tap “Charging this device” 

Tap File Transfer.


You many need to Tap one of the following:
Just Once

Run the program.
This is PowerShell script at this time (a Microsoft program included with Windows).

Programs from outside sources will ask for permission to make changes.allowchanges

PowerShell scripts ask you about execution policy bypass. This allows this instance of the program to run.  If you do not make other changes, it will prompt you every time for this.  For the most part, this is what we recommend.


Answer Y

The Program will prompt you for your device name.
You will see a list of suggestions or a guide to selecting it from Windows File Explorer.

The program will attempt to identify if you have an SD card and an “internal device” and show you a partial list of the files at any location that it thinks have Pictures and Videos t you have taken with your device.

[Future editing note – Note show more examples, Consumer Cellular, Cricket etc:]

This PC\Galaxy J7 Crown\Card\DCIM\Camera\
This PC\Galaxy J7 Crown\Phone\DCIM\Camera

The general template is:
This PC\MTP USB Device\Internal shared storage\DCIM\Camera

You will select the source(s) of the pictures you want to copy.

You will be asked is you want to copy them to to a destination folder by Year, by Year and Month or just to a destination folder.

You will be prompted for the main destination drive.
The default will be : C:\Users\username\Pictures
Any accessible writable drive will be possible, including USB sticks.
(If the number of files to copy > 100 give x time warning, if 500, say, copy to the computer’s hard drive first, then transfer to the USB.

You will have to accept the default or enter a valid destination

If there are any errors, they will written to the screen.  A .txt log file will also be created showing any errors, input and output drives, the number of files copied, not copied etc..

This project was inspired by and is possible thanks to the efforts of thousands of people who have fought for our freedoms.

I cannot convey the importance and impact these heroes have had on our lives.   For your consideration, I offer these two items.

The Four Freedoms by United States President Franklin D. Roosevelt

Freedom of speech
Freedom of worship
Freedom from want
Freedom from fear


Richard Stallman, one of the most influential champions and pioneers in free and open source software, described another set of freedoms.  The web and thousands of other programs, that millions use daily, have been developed with these freedoms as inspiration.

    • The freedom to run the program for any purpose.
    • The freedom to study how the program works, and change it to make it do what you wish.
    • The freedom to redistribute and make copies so you can help your neighbor.
    • The freedom to improve the program, and release your improvements (and modified versions in general) to the public, so that the whole community benefits.


Current Command Line Version of Program:
Download Copy-MTPCameraByMonth.ps1

Click the Search Button and enter PowerShell
CD to the directory where you downloaded the program
Example Command
.\Copy-PhonePics.ps1 “Moto X4\Internal shared storage\DCIM\Camera” C:\JIC\test

This version of the program expects your pics and videos to be in this format
File names follow this pattern yyyyMMdd_HHmmss e.g. 20200104_231922.jpg

In my case it did not work, as my Android 10 Google Fi Moto X4 stores files with either IMG_ or VID_ appended to the name, example


Code Snippets, and Links to Examples of Possible Use

Get filename and filetype
$filePath = “C:\PS\Test.Documents\myTestFile.txt”;
$fileName = (Split-Path -Path $filePath -Leaf).Split(“.”)[0];
$extension = (Split-Path -Path $filePath -Leaf).Split(“.”)[1];

get year

Get Username
Write-Host ‘Your Username is ‘$env:UserName

Get List of Devices
$DeviceName = Get-PnpDevice -Class WPD -PresentOnly  | Select-Object -Property FriendlyName
Write-Host ‘=============’
Write-Host $DeviceName

Find the DCIM directorys for the DeviceName:
Crawl your Android device attached via usb with PowerShell

Interactive examples

This project takes the existing code and makes it interactive
and prompting the user for some confirmations and error checks. Also the existing program
does this
# File names follow this pattern yyyyMMdd_HHmmss e.g. 20200104_231922.jpg
# Files that do not match this pattern are excluded and reported

and that did not work for my phone.
Requirements by user

Step 1:
Connect phone by usb cable to windows computer

Step 2:
tap on phone and change from charging to file transfer

Step 3:
Run Program and allow Execution Policy bypass

This might help determine if you can find the device

Get List of Devices
$DeviceName = Get-PnpDevice -Class WPD -PresentOnly | Select-Object -Property FriendlyName
Write-Host ‘=============’
Write-Host $DeviceName

If more than one device, show the device name names returned from above code snippet with a way to select the device you want

1) Galaxy J7 Crown
2) Moto X4

Enter the number next to the name of your phone
Validate the number enter selected the set input device name
{if can find device error exit}

Step 4:
Find name of phone internal storage and optional SD card
Note: See the link below (Crawl your Android… )for a way to crawl 2 or 3 levels to find the level where the DCIM directory
is. DCIM is a standard use by phone makes and camera makers
Find the DCIM directories for the DeviceName:

Crawl your Android device attached via usb with PowerShell

Crawl your Android device attached via usb with PowerShell

The PowerShell script Crawl_Android.ps1 is capable of crawling your Android device when it is attached via usb.
Just execute Crawl_Android.ps1 and select the device from the menu.

Limited file details

What I found out is that the Shell Namespace API does not provide a lot of details of the file. It is limited to only a couple of fields that are relevant for the
Windows Explorer GUI.
Strangely, a byte-oriented filesize field is not part of it. It only contains a summarized version, e.g. 4 kB or 10 MB. After futher investigation, I noticed that
Windows Explorer has to make a local temporary copy to get all the details in order to populate the information pane. That’s why most operations are so slow!

view raw
hosted with ❤ by GitHub

$o = New-Object com Shell.Application
$folder = $o.NameSpace(0x11)
# ShellSpecialFolderConstants.ssfDRIVES == 0x11
$items = $folder.Items()
for ($i= 0; $i -lt $items.Count; $i++) {
write-output ([string]$i + ": " + $items.Item($i).Name)
$choice = Read-Host "Make your choice"
$android = $items.Item([int]$choice)
$root = $android.GetFolder()
# FolderItem versus FolderItems
$maxdepth = Read-Host "Max depth"
Function Write-Items($item, $depth, $maxdepth) {
if ($depth -ge $maxdepth) {
$indent = ""
for ($i = 0; $i -lt $depth; $i++) {
$indent += " ";
#write-output ($indent + "Name: " + $
if ($item.Title) {
$hash = @{
Name = $item.Title
Size = $null #$item.ParentFolder.GetDetailsOf($item, 2)
Modified = $null #$item.ParentFolder.GetDetailsOf($item, 3)
Parent = $item.ParentFolder.Title
Level = $depth
$Object = New-Object PSObject Property $hash
write-output $object
} else {
$hash = @{
Name = $item.Name
Size = $item.Parent.GetDetailsOf($item, 2)
Modified = $item.Parent.GetDetailsOf($item, 3)
Parent = $item.Parent.Title
Level = $depth
$Object = New-Object PSObject Property $hash
Write-Output $object
if ($item.Count -gt 0) {
# $item is a folder with its own items
for ($i = 0; $i -lt $item.Count) {
$item2 = $item.item($i)
Write-Items $item2 $depth+1 $maxdepth
else {
if ($item.Items) {
$items = $item.Items()
if ($items.Count -gt 0) {
foreach ($i in $items) {
if ($i.IsFolder) {
$folder = $i.GetFolder()
Write-Items $folder ($depth+1) $maxdepth
else {
Write-Items $i ($depth+1) $maxdepth
else {
# .Count == 0 and no Items present
# we don't need to do anything further here
Write-Items $root 0 $maxdepth | Out-GridView

view raw
hosted with ❤ by GitHub

{if can find DCIM error exit}

set the input file path or paths

Step 5:

Check files under DCIM directories for standard format

{if can find any files error exit}
examples file names

$f1=’20200104_231922.jpg’; // default used in existing ps1 file
$f2=’IMG_20181121_183737281.JPG’; // what I see on my device

regex to find year month day

Step 6:
A) If you can find files with a year month day, offer to copy from device to destination
by Year
By Year Month

B) else say, could not find year month day file names, do you want to copy all files to destination

Step 7:
prompt for destination drive. {any accessible drive}
Offer the default as

The default will be : ‘C:\Users\’ concatenated with $env:UserName concatenated with ‘\Pictures’;

Check for destination existence
{if can’t find destination error exit}

Step 8:
The existing program does most of this.

This snippet from that program needs work to incorporate the information gathered above

This needs to be changed and expanded with the information from above

## Copy items from camera by month
# We use the file name to arrange folders
# File names follow this pattern yyyyMMdd_HHmmss e.g. 20200104_231922.jpg
# Files that do not match this pattern are excluded and reported

$FileNameRegex = “^(?\d{4})(?\d{2})(?\d{2})_(?\d{2})(?\d{2})(?\d{2}).*\.(?.+)$” #

$ProgressActivityName = “Copying files from ‘$MTPSourcePath’ to ‘$TargetPath'”

$SkippedFiles = @()
$CopiedFilesCount = 0

foreach ($File in ($CameraItems |Sort-Object -Property Name) ){
#Validate file name matches pattern

Write-Progress -Activity $ProgressActivityName -Status “Working on it” -CurrentOperation “Copying: $($File.Name) – Finished $CopiedFilesCount / $($CameraItems.count)” -PercentComplete (($CopiedFilesCount/$CameraItems.count)*100)

if($File.Name -notmatch $FileNameRegex){
$SkippedFiles += [PSCustomObject]@{
Name = $File.Name
TargetPath = $null
Reason = “Pattern mismatch”
Write-Warning “$($File.Name) is skipped because of pattern”

The destination needs to be set based on the information gathered in step 6

Leave a Reply

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

You are commenting using your 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

This site uses Akismet to reduce spam. Learn how your comment data is processed.