Often I needed to convert a set of files (audio files to different format, text files to different encoding, …) in some directory structure and save results to a new destination while retaining directory structure. In order to walk through directory structure we can use find
command, but if we are to create output in new place, subdirectories have to be created, which is where find
command line gets bit complicated (especially if we have to consider spaces in files/directories names). So here is an example for converting text files encoding:
find . -name "*.txt" -exec bash -c 'mkdir -p "/dest-dir/`dirname "{}"`"; iconv -f utf-8 -t windows-1250 -o "/dest-dir/{}" "{}"' \;