目录假设文件名

时间:2016-05-23 18:29:01

标签: bash

我有一堆视频文件要放入与视频文件同名的目录中减去扩展名(.mov)

例如,给定以下目录,如何编写脚本为每个.mov文件创建一个目录,其名称与文件相同(减去.mov),然后将.mov文件放入该目录?

/Volumes/06a_SD_Video_01/_COLLECTIONS/TR2014_295_Walter_Reed/DER_01/ ├── TR2014_295_10_1a_PM.mov ├── TR2014_295_11_1a_DER_01.mov ├── TR2014_295_12_1a_DER_01.mov ├── TR2014_295_13_1a_DER_01.mov ├── TR2014_295_14_1a_PM.mov ├── TR2014_295_15_1a_DER_01.mov ├── TR2014_295_16_1a_DER_01.mov ├── TR2014_295_17_1a_DER_01.mov ├── TR2014_295_18_1a_DER_01.mov ├── TR2014_295_19_1a_DER_01.mov ├── TR2014_295_19_1b_DER_01.mov ├── TR2014_295_1_1a_PM.mov ├── TR2014_295_20_1a_DER_01.mov ├── TR2014_295_21_1a_PM.mov ├── TR2014_295_22_1a_DER_01.mov ├── TR2014_295_22_1b_DER_01.mov ├── TR2014_295_23_1a_DER_01.mov ├── TR2014_295_2_1a_PM.mov ├── TR2014_295_3_1a_DER_01.mov ├── TR2014_295_4_1a_DER_01.mov ├── TR2014_295_5_1a_DER_01.mov ├── TR2014_295_6_1a_DER_01.mov ├── TR2014_295_7_1a_DER_01.mov ├── TR2014_295_8_1a_DER_01.mov ├── TR2014_295_9_1a_DER_01.mov

1 个答案:

答案 0 :(得分:1)

这是一种方式:

脚本:

cd "$1"
for m in *.mov; do
  d=`echo "$m" | sed 's/\.mov$//'`
  mkdir "$d"
  mv "$m" "$d"
done

用法:

sh <scriptname.sh> "<directory>"

如,

sh mov2dir.sh "/Volumes/06a_SD_Video_01/_COLLECTIONS/TR2014_295_Walter_Reed/DER_01/"