如何将一个目录下的所有文件拷贝到多个目录与文件给定数量的? [英] How to move all the files of a directory into multiple directories with a given number of files?
本文介绍了如何将一个目录下的所有文件拷贝到多个目录与文件给定数量的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含超过27000映像的目录。
I have a directory containing more than 27000 images.
我想这些文件分割成每片含约500图像的文件夹。
I want to split these files into folders each containing around 500 images.
不要紧,他们是如何排序,我只是想将它们分开。
It doesn't matter how they are sorted, I just want to separate them.
推荐答案
下面应该工作:
dest_base="destination"
src_dir="src/"
atfile=0
atdir=0
for file in $src_dir/*; do
if ((atfile == 0)); then
dest_dir=$(printf "$dest_base/%0.5d" $atdir)
[[ -d $dest_dir ]] || mkdir -p $dest_dir
fi
mv $file $dest_dir
((atfile++))
if ((atfile > 500)); then
atfile=0
((atdir++))
fi
done
这篇关于如何将一个目录下的所有文件拷贝到多个目录与文件给定数量的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文