简体   繁体   English

applescript 递归更改文件的时间戳(用于按名称对 FAT32 棒进行排序)

[英]applescript change timestamp of files recursevly (for sorting an FAT32-stick by name)

since there is no tool on mac to sort a USB-stick (FAT32) by name to play music files in a car that cannot sort the files by itself, i want to create a little applescript to do this.由于 Mac 上没有工具可以按名称对 USB 记忆棒 (FAT32) 进行排序以在无法自行对文件进行排序的汽车中播放音乐文件,因此我想创建一个小苹果脚本来执行此操作。 There are tools like "drivesort" on Windows that can do this but since wine is not working on Catalina this is no option for me. Windows 上有诸如“drivesort”之类的工具可以执行此操作,但是由于 Wine 在 Catalina 上不起作用,因此对我来说没有选择。 On mac there are many tools to clean from hidden files on drives, but i haven't found any to sort a FAT by name...在 mac 上有很多工具可以清除驱动器上的隐藏文件,但我还没有找到任何可以按名称对 FAT 进行排序的工具...

my idea was to get the file list, sort it by name (if it is not) and then use the touch command to change to date of the file.我的想法是获取文件列表,按名称对其进行排序(如果不是),然后使用 touch 命令更改文件的日期。 as i know FAT32 stores the files not sorted but only by the time the files were added on the stick.据我所知,FAT32 存储未排序的文件,但仅在将文件添加到棒上时存储。

here is my appescript, but it errors that on the line where "a" will be set, it cannot convert into the expected type:这是我的 appescript,但在设置“a”的行上出错,它无法转换为预期的类型:

tell application "Finder"
    set file_list to every file of entire contents of (choose folder with prompt "Please select directory.")
end tell

repeat with afile in file_list
    set a to quoted form of POSIX path of afile
    display dialog "aktuelle Datei: " & a as string
    do shell script "touch -am " & a
end repeat

what i am doing wrong here?我在这里做错了什么? is there a better simplier way?有没有更好更简单的方法? many thanks!非常感谢!

Finder should be able to sort the files and also adjust the modification dates of each. Finder应该能够对文件进行排序并调整每个文件的修改日期。 So something like this (which I admit I haven't yet tested but will do so when I am in front of a computer) :所以像这样 (我承认我还没有测试过,但是当我在电脑前时会这样做)

set now to the current date

tell application id "com.apple.Finder" to repeat with f in (sort ¬
    the files in my (choose folder)'s entire contents by name)
    set [f's modification date, f's creation date, now] to ¬
        [now, now, now + 5]
end repeat

sorts the selected folder by setting the modification date通过设置修改日期对所选文件夹进行排序

set now to the current date
set MyFolder to choose folder with prompt "Folder to be sorted"

tell application "Finder"
    set SubFolders to every folder of entire contents of MyFolder

    -- sort files in the root of the selected folder
    tell application id "com.apple.Finder"
        repeat with f in ¬
            (sort files in MyFolder by name) as alias list
            set [f's modification date, now] to [now, now + 60]
        end repeat
    end tell

    -- loop through every subfolders
    repeat with aSubFolder in SubFolders
        tell application id "com.apple.Finder"
            set [aSubFolder's modification date, now] to [now, now + 60]
        end tell
        tell application id "com.apple.Finder"
            repeat with f in ¬
                (sort files in aSubFolder by name) as alias list
                set [f's modification date, now] to [now, now + 60]
            end repeat
        end tell
    end repeat
end tell

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM