큰 음악 라이브러리가 ./"Artist Name"/"Album Name"/"audio files"
으로 저장되어 있습니다.루프에서 폴더 병합 및 이동
나는 ./"Artist name --- Album name"/"audio files"
에 다시 구성 그리고 그것이 얼마나 다시 넣어 수 있도록하고 싶습니다.
큰 음악 라이브러리가 ./"Artist Name"/"Album Name"/"audio files"
으로 저장되어 있습니다.루프에서 폴더 병합 및 이동
나는 ./"Artist name --- Album name"/"audio files"
에 다시 구성 그리고 그것이 얼마나 다시 넣어 수 있도록하고 싶습니다.
이 여기에 첫 번째 루프
mkdir "ArtistName-Albumname"
cd "ArtistName/Albumname"
for filename in *; do
mv "$filename" "$ArtistName-Albumname/" ;;
done
입니다 "Artist Name"/"Album Name"
에서 "Artist name - Album name"
#! /usr/bin/env bash
cd /PATH
find . -type f |while read -r line
do
file=${line##*/}
folder=${line%/*}
album=${folder##*/}
folder=${folder%/*}
artist=${folder##*/}
newfolder="$artist - $album"
mkdir -p "$newfolder"
echo mv "$line" "$newfolder"
done
에 위 스크립트를 이해한다면, 당신은 역을 쓸 괜찮을 폴더를 병합하는 스크립트입니다.
고마워! 이 파일은 각 오디오 파일에 대한 mkdir을 수행합니다. 각 앨범에 대해 반복 수행하는 것만으로 폴더 안의 내용을 무시하고 전체 폴더의 이름을 변경하고 이동하는 것이 좋습니다. – klugg
이렇게 생각하면 시작하게 될 것입니다. 그것은 아무것도하지만 당신의 구조를 분석하고 일 필요가 무엇인지 작동하지 않습니다
#!/bin/bash
find . -depth 2 -type d | while IFS= read p
do
p=${p:2} # Trim ./ from start
album=${p##*/} # album is everything after/
artist=${p%/*} # artist is everything before/
newloc="${artist} - ${album}"
echo Would move $artist/$album to ${newloc}
done
샘플 출력 : 하이픈이 자연스럽게에서 발생이있을 수 있으므로
Would move artist1/album1 to artist1 - album1
Would move artist1/album2 to artist1 - album2
Would move artist1/album3 to artist1 - album3
Would move artist1/album4 to artist1 - album4
Would move artist2/album1 to artist2 - album1
Would move artist2/album2 to artist2 - album2
Would move artist2/album3 to artist2 - album3
Would move artist3/album1 to artist3 - album1
Would move artist3/album2 to artist3 - album2
Would move artist3/album3 to artist3 - album3
Would move artist4/album1 to artist4 - album1
Would move artist4/album2 to artist4 - album2
Would move artist4/album3 to artist4 - album3
Would move artist4/album4 to artist4 - album4
Would move artist4/album5 to artist4 - album5
반대의 작업은 까다 롭습니다 앨범 이름이므로 아래 코드에서 하이픈과 구별하기가 어려울 것입니다.
아마추어를 위해서 시간을 좀 보냈습니다. 그러나 여기에 나의 마지막 해결책이 있습니다. 귀하의 의견 @mark @BMW에 감사드립니다.
function flatten() {
echo flattening...
ls -ld --format=single-column */* | while IFS= read albumpath
do
echo Flattening "$albumpath"
artist=${albumpath%/*} # artist is everything before/
echo Artist: "$artist"
echo Album: "$albumpath"
album=${albumpath##*/} # album is everything after/
newfolder="$artist --- $album"
echo Moving "$albumpath" to "$newfolder"
mv "$albumpath" "$newfolder"
done
find . -depth -type d -empty -delete #delete all empty (artist)folders
}
function unflatten() {
ls -ld --format=single-column */ | while IFS= read pathname
do
echo REVERSING "$pathname" ;
artist=${pathname% ---*} # artist is everything before " ---"
echo Artist: "$artist"
if [ ! -d "$artist" ];
then
echo Creating "$artist" folder
mkdir "$artist"
fi
album=${pathname##*--- } # album is everything after "--- "
album=${album%/*} # strip trailing/
echo Album: "$album"
echo Moving "$pathname" "$artist"/"$album"
mv "$pathname" "$artist"/"$album"
done
}
은 '난 당신이 뭘하려 그렇게 tried'거야? 진행 상황을 게시 할 수 있습니까? –