The drive letter may vary depending on drive letters already mapped and assigned to the user. I have solved this with the For/Next to search if the directory exists with the drive letters A-Z.
Expand|Select|Wrap|Line Numbers
- Private Sub cmdTest_Click()
- Dim FSO As Object
- Dim pathTo As String
- Dim FileExtension As String
- Dim intDrive As Integer
- Dim strCamFolder As String
- Dim blnStop As Boolean
- Dim intPhoto As Integer
- Dim pathFrom As String
- Dim FileNames As String
- Set FSO = CreateObject("Scripting.FileSystemObject")
- pathTo = "C:\Users\UserName\Desktop\TEST\"
- FileExtension = "*.jpg"
- intDrive = 65 'starts at Drive Letter "A"
- strCamFolder = ":\DCIM\100NIKON\"
- blnStop = False
- intPhoto = 0
- For i = 1 To 26 'A-Z
- If FolderExists(Chr(intDrive) & strCamFolder) = False Then
- intDrive = intDrive + 1
- Else
- pathFrom = Chr(intDrive) & strCamFolder
- Do
- FileNames = dir(pathFrom & FileExtension)
- If Len(FileNames) = 0 Then
- blnStop = True
- Else
- intPhoto = intPhoto + 1
- FileCopy pathFrom & FileNames, pathTo & "FRa120313a" & intPhoto & ".jpg"
- ' FSO.MoveFile Source:=pathFrom & FileExtension, Destination:=pathTo
- End If
- Loop Until blnStop = True
- intDrive = intDrive + 1
- End If
- Next i
- End Sub
When I use the FSO.MoveFile on Line 33, it will move all photos from the camera to the drive specified without changing the file names (except their parent path).
But when I use the FileCopy on Line 32, it will only copy one photo to the specified directory and rename it.
Ultimately I'd like to just copy the photos rather than move them to avoid any loss of photos during unforeseen failures, AND rename them with the incremental serial numbering suffix. I'd then like to delete each photo from that camera after verifying the copy/transfer/rename was successful. And lastly on my wish list, I'd like to display a MsgBox intNumberPhotos & " transferred."
Thank you for your help.