删除与AppleScript的多个文件 [英] Delete multiple files with applescript

查看:520
本文介绍了删除与AppleScript的多个文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让我们说我有多个文件我想删除,他们正在存储每行一个在 files.txt 文件。我可以将它们删除。

Let’s say I have multiple files I want to delete, and they’re stored one per line in a files.txt file. I can delete them with

set deleteThis to paragraphs of (read "files.txt")

repeat with lineFromFile in deleteThis
    set fileName to POSIX file lineFromFile
    tell application "Finder" to delete file fileName
end repeat

这是逻辑你平时在网上找到 - 逐个删除其中之一,但不是唯一的这是否拧你的放回选项(你必须<大骨节病>⌘ <大骨节病>以Z 多次),它也扮演着垃圾桶的声音一堆次连胜。

This is the logic you usually find online — deleting them one by one, but not only does this screw your "Put Back" option (you have to z multiple times), it also plays the trash sound a bunch of times in a row.

有没有一种方法可以一次删除多个文件,通过在一个阵列存储它们和删除说呢?

Is there a way to delete multiple files at once, say via storing them in an array and deleting that?

修改

由@adayzdone答案是迄今为止最好的,但它在目录失败

The answer by @adayzdone is the best so far, but it fails on directories

推荐答案

尝试:

    set deleteThis to paragraphs of (read "files.txt" as «class utf8»)
    set deleteList to {}

   tell application "Finder"
    repeat with aPath in deleteThis
        try
            set end of deleteList to (file aPath)
        on error
            try
                set end of deleteList to (folder aPath)
            end try
        end try
    end repeat

    delete deleteList
end tell

这篇关于删除与AppleScript的多个文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆