[英]How to rename all the files across different folders into another folder using count in the name?
I am under Ubuntu and I would like to write a bash script such that the following configuration is changed from:我在 Ubuntu 下,我想编写一个 bash 脚本,以便将以下配置更改为:
--images
|--video1
| |--frame1.jpg
| |--frame2.jpg
| |-- ...
| |--frame32.jpg
|
|--video2
| |--frame1.jpg
| |--frame2.jpg
| |-- ...
| |--frame32.jpg
|
|-- ...
|
|--video900
| |--frame1.jpg
| |--frame2.jpg
| |-- ...
| |--frame32.jpg
to到
|--images
|--final_images
| |--frame1.jpg
| |--frames2.jpg
| |-- ...
| |--frame28800.jpg
My goal is to move all the frames for each video in the same directory final_images
.我的目标是将每个视频的所有帧移动到同一目录
final_images
中。 So first I would like to go into every folder and rename every frame such that to frame1, frame2,..., frame28800
(every video has 32 frames and I have 900 videos so the total number of frames I have is 28800).所以首先我想将 go 放入每个文件夹并将每个帧重命名为
frame1, frame2,..., frame28800
(每个视频有 32 帧,我有 900 个视频,所以我的帧总数为 28800)。 Then I would like to move all the renamed frames into final_images
.然后我想将所有重命名的帧移动到
final_images
中。 Any help would be appreciated, I am not very proficient with bash.任何帮助将不胜感激,我不是很精通 bash。
Edit: This is what I tried, being in images folder:编辑:这是我尝试过的,位于图像文件夹中:
A=0;
for i in $(ls -d */); do
for file in $(ls ${i%%} */); do
mv "$(pwd)/${i%%}${file%%}" "$(pwd)/${i%%}${file%%}_$A" ;
((A++));
echo $A ;
done ;
done
These could be the algorithm steps:这些可能是算法步骤:
source_folder=$1
target_folder=$2
mkdir -p $target_folder
echo "procesing..."
count=1
for file in $source_folder/* $source_folder/**/* ; do
if [[ -f $file ]]; then
cp $file $target_folder/frame$count.jpg
echo "source:"$file "target:"$target_folder/frame$count.jpg
count=$((count + 1))
else
echo "$file is not valid or is folder"
fi
done;
echo ""
echo "target_folder: $target_folder"
find $target_folder | sort
Save this and execute with this parameters:保存并使用以下参数执行:
bash merge_frames.sh /tmp/workspace/source/ /tmp/workspace/target
result:结果:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.