pythonshellcsvcommand-lineautomator

How can I compare directory listing against csv list?


(In short, compare csv list against directory listing and show results good and bad.)

I am trying to simplify and expedite a re-occurring process.

I regularly receive multimedia assets (pdfs, word docs, pdfs, mpeg etc) to upload to a website CMS. The list of the assets and the order they appear is determined by a csv file.

I want check the directory has the assets listed in the csv file before I upload (rather than try to import and find files missing afterwards on the clunky proprietary CMS).

I am on a MAC. I just want to run the process and throw the errors report back to the production dept to sort and resupply.

Is there any way to automate this process through Automator, command line or scripting... or anything really?


Solution

  • The answer to your specific, bolded, question is

    "yes, there are many ways to automate this, through command line scripting (bash), python and many others".


    My suggestion would be to try Python, though this is clearly a matter of opinion.

    Your Python code will look something like

    import os
    media_file_name = "media.txt"
    media_file = open(media_filename)
    file_list = media_file.readline()  # assuming its all csv on one line
    for check_file in file_list.split(','):
        if os.path.isfile(check_file):
             print "%s is in place, good" % check_file
        else:
             print "%s is supposed to be here, but isn't" % check_file
    

    I got this code by Googling: