Jump to content

Wanting to auto copy individual folder when a SD/USB device is connected.

xco
Go to solution Solved by Eigenvektor,
28 minutes ago, xco said:

I am open to using a one liner. I can save it on a notepad on the desktop and copy paste it into Command Prompt? 

You can create a .cmd file that you simply need to double click, no copy & pasting needed.

 

Here's an example that's a bit more than one line, but date in batch files isn't as easy as I thought…

@echo off

REM This places the date (yyyy-MM-dd) into ldt
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%

REM This copies the images into a new directory
xcopy E:\DCIM\*.jpg G:\Photographs\Photography_Originals\%ldt%\

You could probably create something a bit more readable with PowerShell

 

Put this into a file (e.g. "copy_images.cmd") and place it on your desktop. Then you can simply double click it to run it.

Hello,

 

I am not a programmer by any means but I do understand the basics of making my way through programming instructions. 😅

I take a lot of photographs and I was hoping to set up a program that will automatically copy the DCIM file from an inserted SD card and create a new folder with the days date as its name and save the file into that new folder on my PC hard drive.

 

I was then also hoping for a secondary program that will backup an individual file to an external SSD whenever that SSD is connected to my PC.

 

I realise this is probably a lot to ask, but google and youtube haven't been helping. I have tried to use Task Scheduler in conjunction with Event Viewer and USBLogView to no avail. (likely because I am unable to code anything from scratch)

 

Please let me know if anyone has any suggestions for this. I am willing to learn the necessary programming language to help me out here. I'm not too keen on using a software downloaded from the internet to do these tasks as my photos are 99% NDA and sensitive. 

 

Thank you,

xco

 

This is a description of the above but i have included the file name paths. 

 image.png.ca379d9fb4ef28dcd4a5dbad7ccbcf64.png

Link to comment
Share on other sites

Link to post
Share on other sites

So if you remove and add the sd card 10 times it would copy the data 10 times on your PC with a different folder name ? Are you sure you want fully automated and not a manually triggered operation ?

Link to comment
Share on other sites

Link to post
Share on other sites

You could fairly easily semi-automate this with two batch files containing a one-liner each. This would be much simpler and less error prone than an automated solution and avoids the issue that @Franck mentions.

 

To create an automated solution you could, as an example, write a Windows service (e.g. using .NET).

  • This service would need to react to devices being inserted or removed (here's an old example from 2010).
  • When a card is inserted, the service could scan the newly attached drive to see if there is a DCIM directory, then copy the files it contains to a new directory on your computer.
  • To avoid duplicates you could place a file on the SD card that contains information about the files you already copied (e.g. name and hash), to allow your program to exclude those the next time

That's going to be a fair amount of work and you'll e.g. need to handle states where the service is busy copying files (or writing hashes) when the card is removed because you're not actively aware it's still doing things. Because of this I'd much rather use a semi-automated script one-liner that you have to purposely trigger.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

47 minutes ago, Eigenvektor said:

You could fairly easily semi-automate this with two batch files containing a one-liner each. This would be much simpler and less error prone than an automated solution and avoids the issue that @Franck mentions.

 

To create an automated solution you could, as an example, write a Windows service (e.g. using .NET).

  • This service would need to react to devices being inserted or removed (here's an old example from 2010).
  • When a card is inserted, the service could scan the newly attached drive to see if there is a DCIM directory, then copy the files it contains to a new directory on your computer.
  • To avoid duplicates you could place a file on the SD card that contains information about the files you already copied (e.g. name and hash), to allow your program to exclude those the next time

That's going to be a fair amount of work and you'll e.g. need to handle states where the service is busy copying files (or writing hashes) when the card is removed because you're not actively aware it's still doing things. Because of this I'd much rather use a semi-automated script one-liner that you have to purposely trigger.

I am open to using a one liner. I can save it on a notepad on the desktop and copy paste it into Command Prompt? 

Link to comment
Share on other sites

Link to post
Share on other sites

13 minutes ago, xco said:

I am open to using a one liner. I can save it on a notepad on the desktop and copy paste it into Command Prompt? 

Yes you can have a simple batch file on your desktop that does the whole process only if you execute it. This have the benefit that you can plugin a sd card if you just want to check something without copying everything over every time it's plugged in.

Link to comment
Share on other sites

Link to post
Share on other sites

28 minutes ago, xco said:

I am open to using a one liner. I can save it on a notepad on the desktop and copy paste it into Command Prompt? 

You can create a .cmd file that you simply need to double click, no copy & pasting needed.

 

Here's an example that's a bit more than one line, but date in batch files isn't as easy as I thought…

@echo off

REM This places the date (yyyy-MM-dd) into ldt
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%

REM This copies the images into a new directory
xcopy E:\DCIM\*.jpg G:\Photographs\Photography_Originals\%ldt%\

You could probably create something a bit more readable with PowerShell

 

Put this into a file (e.g. "copy_images.cmd") and place it on your desktop. Then you can simply double click it to run it.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

1. Create a new briefcase on your boot drive:

https://www.tenforums.com/tutorials/24426-add-briefcase-new-context-menu-windows-10-a.html

 

2. Move the contents of the folder to the briefcase.

 

3. Setup the briefcase to sync with the SD/USB drive

A PC Enthusiast since 2011
AMD Ryzen 7 5700X@4.65GHz | GIGABYTE GTX 1660 GAMING OC @ Core 2085MHz Memory 5000MHz
Cinebench R23: 15669cb | Unigine Superposition 1080p Extreme: 3566
Link to comment
Share on other sites

Link to post
Share on other sites

5 minutes ago, Vishera said:

3. Setup the briefcase to sync with the SD/USB drive

Wouldn't that also delete files from the desktop that are no longer on the SD card? I would assume the contents of the SD card change all the time, when new photos are taken and old ones deleted…

 

The article also notes

Quote

The Briefcase feature has been completely removed starting with Windows 10 build 14942. This tutorial will no longer work starting with this build.

which was released some time before 2017 (1703)

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Franck said:

Yes you can have a simple batch file on your desktop that does the whole process only if you execute it. This have the benefit that you can plugin a sd card if you just want to check something without copying everything over every time it's plugged in.

Thats a good idea. Thank you, I will have a read of @eigenvektor 's  reply. 

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Eigenvektor said:

You can create a .cmd file that you simply need to double click, no copy & pasting needed.

 

Here's an example that's a bit more than one line, but date in batch files isn't as easy as I thought…

@echo off

REM This places the date (yyyy-MM-dd) into ldt
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%

REM This copies the images into a new directory
xcopy E:\DCIM\*.jpg G:\Photographs\Photography_Originals\%ldt%\

You could probably create something a bit more readable with PowerShell

 

Put this into a file (e.g. "copy_images.cmd") and place it on your desktop. Then you can simply double click it to run it.

Thank you, i will fiddle about with this to get it to work with the photos. I do have a question: what is " REM " ?

 

I will let you know if it works out. 🙂

Link to comment
Share on other sites

Link to post
Share on other sites

3 hours ago, Eigenvektor said:

You can create a .cmd file that you simply need to double click, no copy & pasting needed.

 

Here's an example that's a bit more than one line, but date in batch files isn't as easy as I thought…

@echo off

REM This places the date (yyyy-MM-dd) into ldt
for /F "usebackq tokens=1,2 delims==" %%i in (`wmic os get LocalDateTime /VALUE 2^>NUL`) do if '.%%i.'=='.LocalDateTime.' set ldt=%%j
set ldt=%ldt:~0,4%-%ldt:~4,2%-%ldt:~6,2%

REM This copies the images into a new directory
xcopy E:\DCIM\*.jpg G:\Photographs\Photography_Originals\%ldt%\

You could probably create something a bit more readable with PowerShell

 

Put this into a file (e.g. "copy_images.cmd") and place it on your desktop. Then you can simply double click it to run it.

Worked very well. I changed the set date bit with a different solution online. Here's what i got: 

image.png.ab13d2ea787d934b3e5d3f0c5f8dc292.png

 

I plan to jiffy this to work as a potential backup for the files onto an external SSD. You were right - automating it would have probably caused more problems than its worth. Thank you

Link to comment
Share on other sites

Link to post
Share on other sites

14 hours ago, xco said:

a question: what is " REM " ?

A comment (remark), so anything following it is ignored by the interpreter. Basically what you'd do with # or // in a sensible language 😉

 

~edit: the other date solution is locale dependent, so it's not portable between e.g. an English system and a French system, while the for-loop is.

Remember to either quote or @mention others, so they are notified of your reply

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×