File size: 1,153 Bytes
86de37e 9897fc5 86de37e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
#!/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."
|