Search code examples
excelimagecmdcopy

Using Command prompt to copy select images from one folder to another


I have a massive file of .jpg images. I want to copy a select amount of images (400/1600) to another folder which i can send to a customer. I have a list of the image file paths I require in excel so I could do this by copying them over individually but this could take days... is there a way i can do this in command prompt or another method? This is the file path of ones of the images Y:\MMS\Data\Mobile Mapping Final Processed Data\2020-JUL-06_SH075\Track_QSphere\Track_Q-Sphere-14.jpg I would like to copy this across to Y:\MMS_SAMPLE_DATA\finalimages

any help would be very much appreciated on this please


Solution

  • What you can do is Select the range of your file paths then run a simple macro similar to the following.

    First insert a module in your workbook where you store the file paths and create this function.

    Function GetFilenameFromPath(ByVal strPath As String) As String
    If Right$(strPath, 1) <> "\" And Len(strPath) > 0 Then
        GetFilenameFromPath = GetFilenameFromPath(Left$(strPath, Len(strPath) - 1)) + Right$(strPath, 1)
    End If
    End Function
    

    I got this function from this threaad

    Next, create a extremely simple procedure similar to the following in the same module. (No Microsoft Scripting Library needed)

    Sub copy_file_in_selected_range()
    Dim current_range As Range, source_path As String, destination_path As String
    
    destination_path = "C:\temp"
    For Each current_range In Selection
        source_path = current_range.Value
        FileCopy source_path, (destination_path & "\" & GetFilenameFromPath(source_path))
     Next current_range
    End Sub
    

    and change the destination_path to where you want the images to copy to

    Go back to your file path sheet, select the range of file paths Use Alt-F8 to bring up Marco window, select copy_file_in_selected_range and run.

    Please first test in a small batch to make sure it works fine before select a large batch.