
私は現在、膨大なマンガのライブラリを整理中です (ほとんどが画像ファイルですが、それだけではありません)。マンガごとにメイン フォルダがあり、その中には各巻ごとに 1 つのサブフォルダがあります。
ただし、ボリューム フォルダーにはイメージ ファイルのみが含まれる場合もあれば、サブフォルダーが含まれる場合もあります。
選択したマンガフォルダに対して、次のスクリプトを実行したいです:
- どのボリュームフォルダにサブフォルダがあるか確認する
- ボリューム フォルダーのディレクトリ構造をサブフォルダーでフラット化します。すべての画像を親フォルダーに入れてサブフォルダーを消去するのではなく、デスクトップに新しいフォルダーを作成し、そこにサブフォルダーのすべての画像をコピーします。
- デスクトップに作成されたフォルダの名前を元の親フォルダの名前に変更します
前に :
マンガフォルダ
volume1_folder subfolder1 / image1, image2, image3 subfolder2 / image4, image5, image6 subfolder3 / image7, image8, image9 volume2_folder image1, image2, image3, image4, image5, image6, image7, image8, image9 volume3_folder subfolder1 / image1, image2, image3 subfolder2 / image4, image5, image6 subfolder3 / image7, image8, image9
後:
デスクトップ:
volume1_folder image1, image2, image3, image4, image5, image6, image7, image8, image9 volume3_folder image1, image2, image3, image4, image5, image6, image7, image8, image9
元のフォルダはそのまま残しておく必要があります間違った場所に置かれたファイルなどをチェックできます。
現在、私は選択したボリューム フォルダごとにディレクトリ構造をフラット化する AppleScript を使用しています。これにより、コピーされたすべての画像を含む親フォルダにちなんで名付けられた新しいフォルダが内部に作成されます。
できないこと:
- どのボリューム フォルダにサブフォルダがあるかを確認します (各ボリューム フォルダを個別に選択し、そのたびにスクリプトを起動する必要があります)
- 作成されたフォルダをフラット化されたディレクトリ構造でデスクトップに移動する
自分で変更を実装しようとしましたが、新しいフォルダーをデスクトップに移動するか、親フォルダーにちなんで名前を変更するかのどちらかしかできませんでした。2 つの命令 (どちらを最初に配置するか) を配置すると、最初の命令を実行した後にフォルダーが見つからないというエラーが発生します。スクリプトは次のとおりです。
tell application "Finder"
set theTopFolder to (selection as alias)
set theFiles to a reference to every file of (entire contents of folder theTopFolder)
set theNewFolder to make new folder at theTopFolder with properties {name:"Flattened Files"}
duplicate theFiles to theNewFolder
set name of theNewFolder to name of theTopFolder
--move theNewFolder to "Macintosh HD:Users:xx:Desktop:"
end tell
答え1
tell application "Finder"
repeat with f in (get folders of (POSIX file "/Users/username/manga_folder" as alias))
make new folder at desktop with properties {name:(get name of f)}
duplicate files of entire contents of f to result
end repeat
end tell
次のようなシェル コマンドを使用することもできます。
cd ~/manga_folder;for d in *;do mkdir ~/Desktop/"$d";find "$d" -type f|while read f;do cp "$f" ~/Desktop/"$d";done;done
または、GNU cp をお持ちの場合は:
cd ~/manga_folder;for d in *;do mkdir ~/Desktop/"$d";find "$d" -type f -exec gcp -t ~/Desktop/"$d" {} +;done