• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1617
  • Last Modified:

Batch File To Copy Pictures

I am looking for a way to copy all of my digital camera pictures into a folder by using a batch file.  If it's possible, I would like the batch file to read the date that the picture was taken, and make that date the name of the folder.  Once the folder is created, I need the batch to copy all photos to the folder that corresponds to the date the picture was taken . Is this a fairly simple process? Can someone provide a sample of how I would do this, or point me in the right direction? Thanks.
  • 2
1 Solution
This is beyond the capabilities of batch scripting, but could probably be done with vbscript.  Like batch, vbscript runs natively without installing any additional software.  Would that be acceptable?

Also, I don't have a digital camera to test with, but when you connect yours does it show up in the Storage\Disk Management node in Computer Management?  Can you right-click it , hit Change Drive Letter and Paths, click Add, and mount it to an empty NTFS folder on your C: drive?

If so then moving the files from a mounted folder would be a lot easier than trying to grab them directly from the camera.
Assuming all those things are true, paste the script below into a text file with a .vbs extension.  Customize the value of the strSource variable on line 1 with the location of the folder you mounted the camera to.  Customize the value of the strDest variable with the location of the folder to move the photos to.

Running the script will move all pictures from the camera to subfolders named for the dates they were taken.

strSource = "c:\camera mount point"
strDest = "c:\photos"
Set objWMIService = GetObject("winmgmts:\\.\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * From Win32_OperatingSystem")
For Each objItem in colItems
    If InStr(objItem.Caption, "Vista") Or InStr(objItem.Caption, "2008") Then
        intDetail = 12
        intDetail = 25
    End If
Set objFSO = CreateObject("Scripting.FileSystemObject")
If Not objFSO.FolderExists(strDest) Then
    objFSO.CreateFolder strDest
End If
Set objShell = CreateObject("Shell.Application")
Set objSource = objShell.Namespace(strSource)
For Each objFile in objSource.Items
    dtmTaken = objSource.GetDetailsOf(objFile, intDetail)
    If dtmTaken <> "" Then
        strNewFolder = strDest & "\" & ShortDate(dtmTaken)
        If Not objFSO.FolderExists(strNewFolder) Then
            objFSO.CreateFolder strNewFolder
        End If
        objFSO.MoveFile objFile.Path, strNewFolder & "\"
    End If
Function ShortDate(dtmTime)
    strYear = Year(dtmTime)
    strMonth = Right("0" & Month(dtmTime), 2)
    strDay = Right("0" & Day(dtmTime), 2)
    ShortDate = strYear & strMonth & strDay
End Function

Open in new window

thedeal56Author Commented:
Wow, thank you very much.  That is very cool; it works great.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now