我有一個文件夾(稱爲testdir)與子文件夾中的許多不同的文件類型。有許多文件名稱相同但擴展名不同,即使是具有相同名稱/擴展名的文件(但可能不完全相同)。 我需要一個腳本,它只將來自testdir及其子文件夾的mp3和mp4文件存檔到一個存檔文件夾中(而不會將它們放入子文件夾中)。如果archieve文件夾不存在,請創建它。 但是 - 只複製沒有.mp3(同名)的.mp4文件 - 比較.mp3文件,如果有多個相同的名稱並複製它們不相同並重命名它們 - 複製.mp4文件(僅)沒有.mp3(具有相同名稱) 該腳本需要有2個參數,因此它應該像arch arch_dir archive_dir一樣工作,並在用戶使用它時顯示錯誤消息。另外如果source_dir不存在。 這是我走到這一步:腳本來比較mp3和mp4文件
#!/bin/bash
#declare variables
SOURCE_DIR=$1
ARCHIEVE_DIR=$2
#if the user forgets to use 2 arguments:
if [ $# -ne 2 ]
then echo Usage: arch source_dir archieve_dir
fi
#if the source_dir does not exist:
if [ ! -d $SOURCE_DIR ]
then echo ERROR: Source directory is missing!
fi
# if archieve_dir does not exist, create it
if [ ! -d $ARCHIEVE_DIR ]
then mkdir $ARCHIEVE_DIR
fi
echo $ARCHIEVE_DIR created.
cd $ARCHIEVE_DIR
find . -type f \(-iname "*.mp3" -o -iname "-.mp4" \)
# copy all the .mp4 files that have no .mp3 pairs (with the same name)
#copy .mp3 files that have .mp4 identicals (leave mp4s)
# copy and rename the .mp3 files that are not identical but have the same name
任何形式的幫助,非常感謝!在此先感謝
對不起,我剛剛注意到,在標題中我輸入了錯誤的文件類型。我正在尋找mp3和mp4實現。 – astennu
您可以編輯自己的問題,只需點擊問題 –
下方的小編輯鏈接,謝謝!我剛來這地方。 – astennu