Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
Apple Computing Products:
macOS - Operating System
Any way to copy data and skipping corrupt data instead of stopping?
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Raz0rEdge" data-source="post: 1831233" data-attributes="member: 110816"><p>The command is a recursive force copy from source to destination. The force overwrites the destination files if they exist. The recursive will go down the folders and their sub-folders all the way down to the end.</p><p></p><p>It is however still prone to failing on a single file.</p><p></p><p>A crude script would be something like the following:</p><p>[CODE]</p><p>#!/bin/bash</p><p></p><p># Save the source directory</p><p>SRC=$1</p><p></p><p># Save the destination directory</p><p>DEST=$2</p><p></p><p># Jump to the source directory</p><p>pushd $SRC</p><p></p><p># Find a list of top level directories</p><p>find $SRC -type d -d 1 > /tmp/topleveldirs</p><p></p><p>for dir in `cat /tmp/topleveldirs`; do</p><p> pushd $dir</p><p></p><p> # Create the top level directory in the destination folder if it doesn't exist.</p><p> if [ ! -e $DEST/$dir ]; then</p><p> mkdir $DEST/$dir</p><p> fi</p><p></p><p> SDIRS=`find . -type d -d 1`</p><p> if [ -z $SDIRS ]; then</p><p> # This folder only has files</p><p> for file in `ls`; do</p><p> cp $file $DEST/$dir/$file</p><p> if [ $? -ne 0 ]; then</p><p> echo "Unable to copy $dir/$file, moving on...."</p><p> fi</p><p> done</p><p> else</p><p> find $SRC -type d -d 1 > /tmp/subdirs</p><p> for sdir in `cat /tmp/topleveldirs`; do</p><p> pushd $sdir</p><p> if [ ! -e $DEST/$dir/$sdir ]; then</p><p> mkdir $DEST/$dir/$sdir</p><p> fi</p><p> SDIRS=`find . -type d -d 1`</p><p> if [ -z $SDIRS ]; then</p><p> # This folder only has files</p><p> for file in `ls`; do</p><p> cp $file $DEST/$dir/$file</p><p> if [ $? -ne 0 ]; then</p><p> echo "Unable to copy $dir/$file, moving on...."</p><p> fi</p><p> done</p><p> else</p><p> # Time for a recursive function. :)</p><p> fi</p><p> done</p><p> fi</p><p>done</p><p></p><p>[/CODE]</p><p></p><p>Something like this. This is a poorly written script, but let me write something a little more robust and post back.</p><p></p><p>Can you give me a rough idea of folders and the files they hold so I can test it out?</p></blockquote><p></p>
[QUOTE="Raz0rEdge, post: 1831233, member: 110816"] The command is a recursive force copy from source to destination. The force overwrites the destination files if they exist. The recursive will go down the folders and their sub-folders all the way down to the end. It is however still prone to failing on a single file. A crude script would be something like the following: [CODE] #!/bin/bash # Save the source directory SRC=$1 # Save the destination directory DEST=$2 # Jump to the source directory pushd $SRC # Find a list of top level directories find $SRC -type d -d 1 > /tmp/topleveldirs for dir in `cat /tmp/topleveldirs`; do pushd $dir # Create the top level directory in the destination folder if it doesn't exist. if [ ! -e $DEST/$dir ]; then mkdir $DEST/$dir fi SDIRS=`find . -type d -d 1` if [ -z $SDIRS ]; then # This folder only has files for file in `ls`; do cp $file $DEST/$dir/$file if [ $? -ne 0 ]; then echo "Unable to copy $dir/$file, moving on...." fi done else find $SRC -type d -d 1 > /tmp/subdirs for sdir in `cat /tmp/topleveldirs`; do pushd $sdir if [ ! -e $DEST/$dir/$sdir ]; then mkdir $DEST/$dir/$sdir fi SDIRS=`find . -type d -d 1` if [ -z $SDIRS ]; then # This folder only has files for file in `ls`; do cp $file $DEST/$dir/$file if [ $? -ne 0 ]; then echo "Unable to copy $dir/$file, moving on...." fi done else # Time for a recursive function. :) fi done fi done [/CODE] Something like this. This is a poorly written script, but let me write something a little more robust and post back. Can you give me a rough idea of folders and the files they hold so I can test it out? [/QUOTE]
Verification
Name this item 🌈
Post reply
Forums
Apple Computing Products:
macOS - Operating System
Any way to copy data and skipping corrupt data instead of stopping?
Top