Yebulabula
depth-aligned
9897fc5
#!/bin/bash
# Change to the directory with the files
cd /mnt/sda/OpenDlign-Datasets/shapenet/depth_align_img/
# Directory where the subdirectories will be created
base_dir=$(pwd)
# Maximum number of files per directory
max_files_per_dir=10000
# Create a counter to keep track of subdirectory number
dir_counter=1
# Array to hold files
files=(*)
# Total number of files
total_files=${#files[@]}
# Loop through all files and move them to appropriate subdirectories
for (( i=0; i<$total_files; i+=$max_files_per_dir )); do
# Create new subdirectory
new_dir="${base_dir}/part${dir_counter}"
mkdir -p "${new_dir}"
# Compute the slice of files to move
# Bash doesn't handle large arrays well, so we process them in chunks
(( slice_end=i+max_files_per_dir-1 ))
if [ $slice_end -ge $total_files ]; then
slice_end=$total_files
fi
# Move files to new directory
echo "Moving files ${i} to ${slice_end} to ${new_dir}"
mv "${files[@]:$i:$max_files_per_dir}" "${new_dir}"
# Increment the directory counter
dir_counter=$((dir_counter+1))
done
echo "All files have been moved into subdirectories."