[SOLVED] Does a file exist

Posted on
Sat Apr 05, 2014 8:01 pm
300BlkPlinker offline
Posts: 26
Joined: Jan 20, 2014

[SOLVED] Does a file exist

Sorry for the newbie question. I have IFTTT dropping a file in Dropbox that I can see on my Mac installed from Indigo. I'm a fairly good shell scripter but losing patient in finding a useful python or Apple script example through a google search.

I just want to check to see if a file exists and delete it after telling a Trigger that the file was true and take action.

Thanks for helping a newbie along. Now back to that python training video....

Posted on
Sat Apr 05, 2014 9:08 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Does a file exist

Code: Select all
import os, sys  # don't think you need sys, just os

if os.path.isfile('/Users/yourID/dropbox/thefile'):
    do whatever if it exists
else:
    do whatever if it does not exists

os.remove("/Users/yourID/dropbox/theFile" ) # will delete "theFile" in directory ~/dropbox
os.rename("/Users/yourID/dropbox/theFile" ) # will rename it


check out https://docs.python.org for more examples
Naturally replace yourID and dropbox and theFile etc with the right strings.

hope that helps.
Karl

Posted on
Sat Apr 05, 2014 11:23 pm
kw123 offline
User avatar
Posts: 8363
Joined: May 12, 2013
Location: Dallas, TX

Re: Does a file exist

and in aplescript, copied from http://www.quartzcity.net/2012/04/27/applescript-code-for-determining-if-file-exists/

Code: Select all
tell application "Finder"
    if exists file "Macintosh HD:Users:yourID:dropbox:theFile" then
        display dialog "it exists"
    else
        display dialog "it does not exist"
    end if
end tell

Posted on
Mon Apr 07, 2014 5:47 am
300BlkPlinker offline
Posts: 26
Joined: Jan 20, 2014

Re: Does a file exist

Thanks a bunch. Now back to my immersion into Python.....

Page 1 of 1

Who is online

Users browsing this forum: No registered users and 4 guests