首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用applescript通过扩展名将文件移动到新文件夹,并保留子文件夹名称

如何使用applescript通过扩展名将文件移动到新文件夹,并保留子文件夹名称
EN

Stack Overflow用户
提问于 2012-08-14 01:15:24
回答 1查看 1.9K关注 0票数 1

这就是我想要做的。

我有一个包含JPG和RAW格式照片的文件结构。这是一个名为"Photos“的文件夹,其中包含按日期排序的子文件夹。我只想将原始照片复制到新文件夹"Photos RAW“中,但按拍摄/创建日期保留结构。

我可以使用automator或applescript将文件复制到新的目录中,但是如何使用applescript遍历目录树,以便覆盖所有子文件夹?

EN

回答 1

Stack Overflow用户

发布于 2012-08-14 05:40:19

尝尝这个。您将看到我使用了“完整内容”来获取子文件夹中的文件。

代码语言:javascript
复制
set extensionToFind to "raw"

set topLevelFolder to (choose folder) as text
set pathCount to count of topLevelFolder

tell application "Finder"
    -- get the files
    set rawFiles to files of entire contents of folder topLevelFolder whose name extension is extensionToFind
    if rawFiles is {} then return

    -- setup the folder where the files will be moved
    set rawFolder to ((container of folder topLevelFolder) as text) & "Photos_Raw:"
    do shell script "mkdir -p " & quoted form of POSIX path of rawFolder

    repeat with aFile in rawFiles
        set aFileContainer to (container of aFile) as text
        if topLevelFolder is equal to aFileContainer then
            -- here the file is at the top level folder
            set newPath to rawFolder
        else
            -- here we calculate the new path and make sure the folder structure is in place
            set thisFile to aFile as text
            set subFolderPath to text (pathCount + 1) thru -((count of (get name of aFile)) + 1) of thisFile
            set newPath to rawFolder & subFolderPath
            do shell script "mkdir -p " & quoted form of POSIX path of newPath
        end if

        move aFile to folder newPath
    end repeat
end tell
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11939117

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档