Skip to content

Instantly share code, notes, and snippets.

@mibmo
Created January 15, 2024 14:55
Show Gist options
  • Save mibmo/55b086ac48433b8c2afa7b4bf85bd5d8 to your computer and use it in GitHub Desktop.
Save mibmo/55b086ac48433b8c2afa7b4bf85bd5d8 to your computer and use it in GitHub Desktop.
Copy files to a destination one at a time.

Simple wrapper script for cp that copies files one at a time and provides some extra goodies. Useful when you want them all to be in contiguous regions of memory (i.e. 1 extent per file, as is required by some tools).

My usage is mainly putting ISOs on a fat32 SD card for Gamecube, as they can't be more than 32 extents or else the Gamecube will fail to read them.

#!/usr/bin/env bash
_basename=$(basename "$0")
[ $# -lt 2 ] && printf "Usage: %s SOURCE... DEST\nExample: %s iso/*.nkit.iso /mnt/games\n" "$_basename" "$_basename" && exit 1
set -e
_dest="${!#}"
_total=$(($# - 1))
_current=0
for source in "${@:1:$# - 1}"; do
_current=$((_current + 1))
_name=$(basename "$source")
printf "[%s/%s]\tCopying %s:" "$_current" "$_total" "$_name"
_start=$(date -u +%s%3N)
cp "$source" "$_dest/$_name" && \
printf " Success!" || \
printf " Failed :("
_end=$(date -u +%s%3N)
type qalc >/dev/null && echo " [took $(qalc -t "|$_end - $_start|milliseconds to seconds")]"
sleep 0.2
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment