bash - create book from filesystem -


a file system represents book directory representing each chapter , each chapter section, each page/.png file in directory p page of section q of chapter n. page 1 listed 0/0/0 page 456 might third chapter, , second section's page 4 making 2/1/3 directory containing of other pages/.png files.

how bash script recursively search through each directory , organize corresponding pages right page file system read book/pdf? page 1 (0/0/0 in file system) in new directory shiny label displaying 1 or 001 while page/file 456 (2/1/3) displayed wonderful 456?

i've found couple similar problems use following,

find . type -d | while read -r d '' file; mv .'{$d} done 

which finds directories within . gets stuck renaming files. hunted down following script.

source

#!/bin/bash cd list=find `"path/to . " -type d`     directory in $list;     echo "directory=$directory"     cd $directory     imglist="ls | grep '\.png'"     file in $imglist;         mv home/     done     cd done #i didn't write either of these 

but 2 levels.

so how best make go messy file system 1 simplified directory.

if understand right, following help

bookroot='.' #the directory chapters final="./finalbook" #the destination  pages=( $(find "$bookroot"/[0-9]* -name \*.png -print | sed "s:$bookroot/::" | sort -t/ -k1n -k2n -k3n) ) in "${!pages[@]}"      echo cp "$bookroot/${pages[$i]}" "$final/$((i+1))_of_${#pages[@]}.png" done 

this dry run. if satisfied, remove echo.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -