2 # Desc: Zero-pad working dir files with initial digits for sorting
7 find .
-mindepth 1 -maxdepth 1 -type f
-exec basename '{}' \
; ;
10 # Find the maximum number of leading digits in the filenames of working dir
11 max_digits
="$(list_files | sed -e 's/[^0-9].*//' | awk '{ if(length > L) L=length } END { print L }')";
12 # declare -p max_digits; # debug
14 # Loop over the files and rename them
15 while read -r file; do
17 if [[ ! "$file" =~
$re ]]; then continue; fi;
19 # Extract the leading digits
20 digits
="$(echo "$file" | sed 's/\([0-9]*\).*/\1/')";
22 padded_digits
="$(printf "%0${max_digits}d
" "$digits")";
23 # Construct the new filename
24 new_file
="${padded_digits}${file#${digits}}";
26 mv -n "$file" "$new_file"
27 # declare -p file new_file; # debug
36 # Author: Steven Baltakatei Sandoval