0
我們有哪些需要被重新命名,並轉向基於在CVS文件的文件名信息的另一個目錄中的文件的目錄。 的CVS文件的內容是:
A10324687,ahgk1ff0023
A10324698,cru1ff0129從CVS文件數據解析猛砸查找和移動文件
源文件夾具有以下層次:
/Server/Archive/A/AHGK1/AHGK1FF0001_0200/ahgk1ff0023.pdf
/Server/Archive/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.ai
/Server/Archive/B/BFKR3/BFKR3FF0001_0200/bfkr3ff0018.pdf
/Server/Archive/B/BFKR3/BFKR3LC0001_0200/bfkr3lc0018.pdf
/Server/Archive/C/CRU1/CRU1FF0001_0200/cru1ff0129.ai
/Server/Archive/C/CRU1/CRU1FF0001_0200/cru1ff0129.pdf
的腳本行動的結果和重命名
ahgk1ff0023.pdf to: /Server/Art/A10324687_ahgk1ff0023.pdf
在文件名和路徑中的字符的數目而變化。 因此,我認爲有必要使用查找功能與輸入從具有基本名減去擴展csv文件。 下面的腳本對本地文件執行好,但是從網絡共享文件 運行抓取。有什麼建議麼?
#!/bin/bash
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/SKU.log
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/SKU_pdf.log
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/Stamped_PDFs.log
date +"DATE: %a %m/%d/%Y TIME: %r Auto" >> /Volumes/Serve/Users/Admin/Logs/Removed_PDFs.log
#Directory for source files to br moved and renamed
src=/Volumes/Serve/Archive
#Directory in which the files are move to
dest=/Volumes/Serve/Art/
IFS=','
while read new old; do
ai=$(find $src -name $old.ai)
pdf=$(find $src -name $old.pdf)
#Following varible is used to stamp the pdf file with the "New" number from the csv input
pdfout="$dest$new"_"$(basename $pdf)"
stamper=/Users/Admin/Desktop/TMP/stamp.pdf
ait=$(find $src -name $old.ait)
eps=$(find $src -name $old.eps)
tiff=$(find $src -name $old.tiff)
tif=$(find $src -name $old.tif)
psd=$(find $src -name $old.psd)
fh8=$(find $src -name $old.fh8)
fh9=$(find $src -name $old.fh9)
noExt=$(find $src -name $old)
#This is where the pdf files get stamped with the "New" number
echo $new" -> "$old" -> "$pdfout$(basename $pdf) >> /Volumes/Serve/Users/Admin/Logs/SKU_pdf.log
gs -q -sDEVICE=pdfwrite -o $stamper -c "<< /PageSize [792 612] >> setpagedevice 18 586 moveto /Helvetica-Bold_Italic findfont 14 scalefont setfont ("$new") show"
pdftk $pdf stamp $stamper output $pdfout verbose | grep .pdf$ >> /Volumes/Serve/Users/Admin/Logs/Stamped_PDFs.log
rm -f -v $pdf >> /Volumes/Serve/Users/Admin/Logs/Removed_PDFs.log
#The following moves the remaining file types if they exist.
mv -v $ai $dest${new}'_'${old}.ai >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $ait $dest${new}'_'${old}.ait >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $eps $dest${new}'_'${old}.eps >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $tiff $dest${new}'_'${old}.tiff >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $tif $dest${new}'_'${old}.tif >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $psd $dest${new}'_'${old}.psd >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $fh8 $dest${new}'_'${old}.fh8 >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $fh9 $dest${new}'_'${old}.fh9 >> /Volumes/Serve/Users/Admin/Logs/SKU.log
mv -v $noExt $dest${new}'_'${old} >> /Volumes/Serve/Users/Admin/Logs/SKU.log
done < /Users/Admin/Desktop/List.csv
將find查找爲所有文件名作爲目標,即'find $ src -name $ old.psd -name $ old.tif ....'將其發送到'|同時讀取文件名;在* .pdf中執行$ {filename})... ;;; * .tif)... ;;; esac'。如果預計文件名中包含空格或其他非字母數字,請參閱-print0選項以查找和xargs。這裏有100多個有關該組合的帖子。祝你好運。 – shellter 2012-01-27 04:56:38