Your best friend for file transfer.

Fetch application logoFetch

Scripting a delete of a directory (5 posts)

This is an archived topic. The information in it is likely to be out-of-date and no longer applicable to current versions of Fetch.
  • Started 10 years ago by tkale
  • Latest reply 7 years ago from Scott McGuire
  • tkale Member

    I am trying to create an applescript to delete the contents of a directory. I sure would appreciate someone helping me with the proper FTP and AppleScript commands? :confused:

    Posted 10 years ago #

  • Jim Matthews Administrator

    Here's a script that should work (replace host, userid, password and path with the information for your situation):

    tell application "Fetch 4.0.3"
    open url "ftp://userid :password@host/path/"
    set allnames to name of every remote file
    repeat with aname in allnames
    set aname to (aname as string)
    delete remote file aname
    end repeat
    end tell

    Thanks,

    Jim Matthews
    Fetch Softworks

    [This message has been edited by JimMatthews (edited 12-26-2003).]

    Posted 10 years ago #

  • tkale Member

    Thanks Jim!

    Happy Holidays!

    Posted 10 years ago #

  • seg Member

    This is great - I have been trying to figure out how to do this. I tried adding:

    set allnames to name of every remote file whose name extension is "jpg"

    So I can delete specific files, but it didn't work. Am I doing something wrong or is there another way to do this?

    Originally posted by JimMatthews:

    Here's a script that should work (replace host, userid, password and path with the information for your situation):

    tell application "Fetch 4.0.3"
    open url "ftp://userid :password@host/path/"
    set allnames to name of every remote file
    repeat with aname in allnames
    set aname to (aname as string)
    delete remote file aname
    end repeat
    end tell

    Thanks,

    Jim Matthews
    Fetch Softworks

    [This message has been edited by JimMatthews (edited 12-26-2003).]

    Posted 7 years ago #

  • Scott McGuire Administrator

    Hi seg,

    Hi,

    Unfortunately, the AppleScript clause "every remote file whose property is foo" doesn't work with Fetch.

    Here is a script that will do what you want:

    tell application "Fetch"
    open url "ftp://fetchtst:@test.fetchsoftworks.com/sandbox/000newf2/test"
    set allfiles to every remote file
    set namelist to {}
    repeat with afile in allfiles
    if the (name extension of afile) is "jpg" then
    set namelist to namelist & {((name of afile) as string)}
    end if
    end repeat
    repeat with aname in namelist
    delete remote file aname
    end repeat
    end tell

    This builds a list of names and then deletes everything in that list; if you delete inside the first repeat loop you might mess up the indexing and skip some files and/or try to delete some non-existent files.

    Another way to accomplish this, if you're using Fetch 5.1, is to use Fetch's Automator support to create an Automator workflow to do the same thing.

    Fetch has Automator actions for selecting, filtering, and deleting files, among others. And unless you're an experienced AppleScript user, it's easier to use Automator to accomplish things like this than figuring out what the right AppleScript is.

    For more information about Fetch's Automator support, see the Automator actions and Using Automator with Fetch topics in Fetch Help - the latter has an example of deleting files based on certain criteria. And if you run into problems or questions, you can ask here.

    (Fetch 5.1 is a free upgrade for users of Fetch 5.0 and later, and requires Mac OS X 10.3.9 or later.)

    Thanks,

    Scott McGuire
    Fetch Softworks

    Posted 7 years ago #

Topic closed

This topic has been closed.