#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0

    Search/copy file script help


    So I am writing a program with Python 3.3 trying to search for .JPGs on a given drive and copy them to another specified drive. The problem is with what I am using now I will pull all .jpg's, including program icons and system icons, etc. Is there any way to specify if endswith(.jpg) && 'fromPhone()': execute copying. Essentially what I am asking, is if there is any way to look into the metadata of the .jpg or something to see if it was taken from a cell phone? If not a cell phone is there another common way to differentiate .jpg files at all except by name? Thanks to anyone who can push me in the right direction and here is my code as of now. I haven't added the copying functionality yet obviously.

    Code:
    import os
     
    # Initialize folder to search and where to store picture locations.
    folder = 'C:\\'
    file_list = []
    
    print ("Files ending with .jpg in folder %s:" % folder)
    
    # Walk through directories on drive specified(folder) to grab all files with .jpg extensions.
    for (paths, dirs, files) in os.walk(folder):
        for file in files:
            if file.endswith(".jpg"):
                file_list.append(os.path.join(paths, file))
     
    print (file_list)
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,856
    Rep Power
    481
    I'd use the identify program from imagemagick.com with a shell script for this project.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    2
    Rep Power
    0
    Originally Posted by b49P23TIvg
    I'd use the identify program from imagemagick.com with a shell script for this project.
    Thanks for the advice. I looked over it a bit I just am not sure what would be the best way to determine a 'real' image(taken from phone or camera, etc.) from an icon image or images within all my program folders. Shrunk down the search to just search the users folder because it was returning too many damn files without using something like imagemagick. Anyways I updated code to copy the files but having a tough time determining the best way to differentiate types of pictures(although I am thinking taking only pictures of a certain resolution?).

    Code:
    import os
    import shutil
    
    # Make a folder in the pictures path of the computer named '/phb' or edit path.
    # Initialize folder to search and where to store picture locations.
    # If you want to grab pictures from another location edit the folder pathing to be 
    # the path you want.
    
    folder = 'C:\\users'
    file_list = []
    
    print ("Files ending with .jpg in folder %s:" % folder)
    # Walk through directories on drive specified(folder) to grab all files with .jpg extensions.
    for (paths, dirs, files) in os.walk(folder):
        for file in files:
            if file.endswith(".jpg"):
                file_list.append(os.path.join(paths, file))
                
                
    #Uses shutil.copy2 function to copy files in file_list to new /dir/
    for j in file_list:
        shutil.copy2(j, 'c:/users/pictures/phb')

IMN logo majestic logo threadwatch logo seochat tools logo