0

次のファイルを含むフォルダーがあります。

Elephant.19864.archive.other.pdf
Elephant.17334.other.something.pdf
Turnip.19864.something.knight.pdf
Camera.22378.nothing.elf.pdf

これらのファイルを次の構造に移動したい

Archive
    Elephant
        Elephant.19864.pdf
        Elephant.17334.pdf
    Turnip
        Turnip.19864.pdf
    Camera.HighRes
        Camera.HighRes.22378.pdf

生成されたファイルは、1 つまたは複数の単語、一連の番号、その他の単語、拡張子で構成されます。これらを数字の前の単語または単語という名前のフォルダーに移動し、数字と拡張子 (この場合は .pdf) の間のすべての単語を削除します。

フォルダが存在しない場合は、作成する必要があります。

これは Automator や AppleScript を使えば簡単にできると思っていたのですが、どうもうまくいきません。

もしそうなら、Automator/AppleScript を使ってこれは簡単ですか?

4

1 に答える 1

3

それは簡単です、それは最初は明白ではありません。あなたが始めるためのいくつかのこと。

ファイル名を解析してフォルダ名を取得するには、名前をリストに分ける必要があります...

set AppleScript's text item delimiters to {"."}
set fileNameComponents to (every text item in fileName) as list
set AppleScript's text item delimiters to oldDelims
--> returns: {"Elephant", "19864", "archive", "other", "pdf"}

リストには1ベースのインデックスがあるため、アイテム1は「Elephant」、アイテム5は「pdf」です。ファイル名を一緒にマッシュするために必要なのはこれだけです

set theFileName to (item 1 of fileNameComponents & item 2 of fileNameComponents & item 5 of fileNameComponents) as string

フォルダを作成するには、次を使用します...

tell application "Finder"
    set theNewFolder to make new folder at (theTargetFolder as alias) with properties {name:newFolderName, owner privileges:read write, group privileges:read write, everyones privileges:read write}
end tell

ファイルを移動するために必要なのはこれだけです...

tell application "Finder"
    set fileMoved to move theTargetFile to theTargetFolder
end tell

ファイルの名前を変更するには、次のようなものを使用します...

set theFileToRename to theTargetFilePath as alias -- alias is important here
set name of theFileToRename to theFileName

最初にすべてのターゲットファイルのリストを作成し、次にリスト内のファイルごとにその名前に基づいてフォルダーを作成し、ファイルを移動して、最終的な場所に移動したら名前を変更することをお勧めします。

味に塩を加えます。

于 2010-10-06T18:53:14.127 に答える