
나는 거대한 만화 라이브러리(주로 이미지 파일만은 아님)를 정리하는 중입니다. 각 만화에는 각 볼륨마다 하나씩 하위 폴더가 포함된 기본 폴더가 있습니다.
그러나 볼륨 폴더에 이미지 파일만 포함되는 경우도 있고 하위 폴더가 포함되는 경우도 있습니다.
선택한 만화 폴더에 대해 다음과 같은 스크립트를 원합니다.
- 어떤 볼륨 폴더에 하위 폴더가 있는지 확인
- 하위 폴더로 볼륨 폴더의 디렉터리 구조를 평면화합니다. 상위 폴더에 이미지를 모두 넣고 하위 폴더를 지우는 것보다 바탕화면에 새 폴더를 만들고 그 안에 있는 하위 폴더의 이미지를 모두 복사해 주는 것이 좋을 것 같습니다.
- 원래 상위 폴더 다음에 데스크탑에 생성된 폴더의 이름을 바꿉니다.
전에 :
망가_폴더
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를 사용합니다. 내부에 복사된 모든 이미지가 포함된 상위 폴더의 이름을 딴 새 폴더가 내부에 생성됩니다.
그렇지 않은 것:
- 어떤 볼륨 폴더에 하위 폴더가 있는지 확인합니다(각 볼륨 폴더를 개별적으로 선택하고 매번 스크립트를 실행해야 함).
- 평면화된 디렉터리 구조로 생성된 폴더를 데스크탑으로 이동합니다.
변경 사항을 직접 구현하려고 시도했지만 새 폴더를 데스크탑으로 옮기거나 상위 폴더 이름을 따서 이름을 바꿀 수 있었습니다. 두 가지 명령(먼저 넣는 명령이 무엇이든)을 넣으면 첫 번째 명령을 실행한 후 폴더를 찾을 수 없다는 오류가 발생합니다. 스크립트는 다음과 같습니다.
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