473,386 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Copy and rename photos from camera to directory

I want cmdButton_Click() event to move all photos found on the camera (of varying Drive Letter) to a specified directory with a specified file name followed by an increment serial number.

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
  1. Private Sub cmdTest_Click()
  2.     Dim FSO As Object
  3.     Dim pathTo As String
  4.     Dim FileExtension As String
  5.     Dim intDrive As Integer
  6.     Dim strCamFolder As String
  7.     Dim blnStop As Boolean
  8.     Dim intPhoto As Integer
  9.     Dim pathFrom As String
  10.     Dim FileNames As String
  11.  
  12.         Set FSO = CreateObject("Scripting.FileSystemObject")
  13.         pathTo = "C:\Users\UserName\Desktop\TEST\"
  14.         FileExtension = "*.jpg"
  15.         intDrive = 65 'starts at Drive Letter "A"
  16.         strCamFolder = ":\DCIM\100NIKON\"
  17.         blnStop = False
  18.         intPhoto = 0
  19.  
  20. For i = 1 To 26 'A-Z
  21.     If FolderExists(Chr(intDrive) & strCamFolder) = False Then
  22.         intDrive = intDrive + 1
  23.     Else
  24.         pathFrom = Chr(intDrive) & strCamFolder
  25.  
  26.         Do
  27.             FileNames = dir(pathFrom & FileExtension)
  28.             If Len(FileNames) = 0 Then
  29.                 blnStop = True
  30.             Else
  31.                 intPhoto = intPhoto + 1
  32.                 FileCopy pathFrom & FileNames, pathTo & "FRa120313a" & intPhoto & ".jpg"
  33. '                FSO.MoveFile Source:=pathFrom & FileExtension, Destination:=pathTo
  34.             End If
  35.         Loop Until blnStop = True
  36.  
  37.         intDrive = intDrive + 1
  38.     End If
  39. Next i
  40.  
  41. End Sub
I seem to be having trouble figuring out what to write between lines 31-33.

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.
Dec 3 '13 #1

✓ answered by zmbd

While I take a few moments to digest your code, you might find the answer in the following tutorial: Using The FileSystemObject With VB and VBA

6 2322
zmbd
5,501 Expert Mod 4TB
While I take a few moments to digest your code, you might find the answer in the following tutorial: Using The FileSystemObject With VB and VBA
Dec 4 '13 #2
zmbd
5,501 Expert Mod 4TB
page two of the linked tutorial, use the move/copy property of the folder to either move or copy the files from you camara to the correct location. Then use the files-colection and rename the files within that folder.
I thought that could be done; however, I don't use the FSO very often.
Dec 4 '13 #3
ADezii
8,834 Expert 8TB
You can perform the Move & Rename in a single Operation. The following Code will Move the File Test.mdb from the C:\Test\ Folder to the C:\Stuff\ Folder renaming it in the process to the Value of intCtr & .mdb.
Expand|Select|Wrap|Line Numbers
  1. Dim FSO As Object
  2. Dim strSource As String
  3. Dim strDest As String
  4. Dim intCtr As Integer
  5.  
  6. Set FSO = CreateObject("Scripting.FileSystemObject")
  7.  
  8. intCtr = intCtr + 1
  9.  
  10. strSource = "C:\Test\Test.mdb"
  11. strDest = "C:\Stuff\"
  12.  
  13. FSO.MoveFile Source:=strSource, Destination:=strDest & CStr(intCtr) & ".mdb"
  14.  
Upon completion:
Expand|Select|Wrap|Line Numbers
  1. C:\Test\Test.mdb ==> C:\Stuff\1.mdb
Dec 4 '13 #4
zmbd
5,501 Expert Mod 4TB
ADezii: You can perform the Move & Rename in a single Operation.
SgtTurbo: 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
Which is why I thought the files collection:
Expand|Select|Wrap|Line Numbers
  1. For Each zFile In zfiles
  2. Next
Could use the copy, with the rename in the loop, then in a seperate loop start some sort of validation
I really don't have time to write and test the code today.

Or is this not the right logic? It is past my lunch time and I haven't gotten to burn anything in the lab today (-_-)

-z
Dec 4 '13 #5
Thanks @zmnd, that article helped me a lot. This is part of what I ended up using:
Expand|Select|Wrap|Line Numbers
  1.    Dim FSO As Object
  2.     Dim Drv As Object
  3.     Dim d As Object
  4.     Dim File As Object
  5.         Set FSO = CreateObject("Scripting.FileSystemObject")
  6.         Set Drv = FSO.Drives
  7.             For Each d In Drv
  8.                 If d.isready And FolderExists(d & "\DCIM\100NIKON\") Then
The "For Each d in Drv" returned a list of drive letters and eliminated my need to loop through every possible Drive letter. I could then test the few drives that were returned for my specific folder hierarchy path to ensure I'm looking at my camera.

As for my needing to copy, rename and then delete the files (in that order) I ended up doing something like this:
Expand|Select|Wrap|Line Numbers
  1. FileCopy pathFrom & FileNames, pathTo & "FRi120313a" & intPhoto & ".jpg"
  2. Kill pathFrom & FileNames
The FileCopy line allowed me to rename the file at the same time as it copied. I then execute the Kill line immediately afterwards in each loop. This is likely not necessary, but we used to have a batch file (I think thats what it's called) that would at times fail, especially if interrupted by anything: like being unplugged, losing power...) and the photos would have already been deleted. So that original Batch file was modified to only copy the photos and leave the originals on the camera requiring the user to delete them manually on the camera themselves after verifying the transfer was successful.

I think this method will work, but certainly open to any input regarding anything I may be overlooking.
Dec 4 '13 #6
zmbd
5,501 Expert Mod 4TB
before you kill the file, you should go ahead and check that it is there and that at least the file size match.
Dec 4 '13 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: John Baker | last post by:
Hi: I need to copy the entire directory that my .mdb file is sitting in to another drive and directory, and am having trouble with the syntax. The following is intended to copy the contents...
2
by: Matthew | last post by:
I need to develop a macro that upon building a project in VB.NET will copy a configuration file from the project directory to the \Bin directory. Based upon the active build configuration, the...
1
by: Avi | last post by:
Hi All, I am using following function to copy a file. System.IO.File.Copy(sourcefile,destFile); I am giving absolute path in destFile. (eg. "C:\avi.txt") After execution of this call, my...
2
by: Paul | last post by:
I need to copy files from an ftp directory to a web-accessible directory and then delete the files in the ftp directory. (I am doing it this way because web-based form upload can not exceed 2MB...
1
by: dkmarni | last post by:
Hi, I am trying to do this perl script, but not able to complete it successfully. Here is the description what the script has to do.. Accept two and only two command line arguments. Again,...
7
by: SmartPHP | last post by:
Dear friends i want to copy the images from one directory on server and paste them into another directory on my local computer....can someone tell me how can do that..it'll be a great help for...
1
by: ogo796 | last post by:
hi everyone i upload files everyday to the server using a php coded program , it works from other computers but not on the others. Could this be a problem with http headers of specific computers...
0
by: Jeremy | last post by:
We have files arriving via ftp to a server which is on a different domain than the intranet webserver. I want to be able to manipulate these files from the website. Both domains are within the...
7
by: prasadrallabandi | last post by:
Hello every one, my question is how to copy from one directory to another directory (Windows)? clearly: c:\perl> present working directory I have to copy all the text files(*.txt), lets...
2
by: foss | last post by:
hi all, I am not able to copy file from a directory in the server to another directory. Here, the source is outside the web root directory and the destination is inside the web root directory. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.