[RndTbl] script for file copy

Kevin McGregor kevin.a.mcgregor at gmail.com
Wed Jul 7 15:16:37 CDT 2010


Great, but he will still want the slashes converted to underscores, will he
not? I hope he doesn't have any underscores already in any directory or file
names, else it will be non-reversible (and a little confusing).

Kevin

On Wed, Jul 7, 2010 at 2:09 PM, Adam Thompson <athompso at athompso.net> wrote:

> I've had to do this before... there are some tools that'll do it for you,
> essentially you want the UNIX version of MS-DOS's "UPDATE" command.
> I would look at "rsync", used in local mode, use something like
>
>        $ rsync -a --existing SRCDIR DSTDIR
>
> It is of course possible to do this in a shell script, but it's tricky to
> handle the recursion correctly unless you use an iterative find/grep series,
> which gets very expensive in terms of CPU time.
>
> The best non-recursive technique I can think of would be something like:
>        #!/bin/sh
>        SRC="$1"
>        DST="$2"
>        T1=$(mktemp)
>        T2=$(mktemp)
>        find "${SRC}" -type f -print | sed -e "s/^${SRC}//" | sort > "${T1}"
>        find "${DST}" -type f -print | sed -e "s/^${DST}//" | sort > "${T1}"
>        comm -12 "$T1" "$T2" | while read F ; do
>                cp "${SRCDIR}${F}" "${DSTDIR}${F}"
>        done
>
> -Adam
>
> > -----Original Message-----
> > From: roundtable-bounces at muug.mb.ca [mailto:roundtable-
> > bounces at muug.mb.ca] On Behalf Of VE4ER / Andy
> > Sent: Wednesday, July 07, 2010 12:10 PM
> > To: MUUG Roundtable
> > Subject: [RndTbl] script for file copy
> >
> > Can anybody suggest a script to copy files from one directory structure
> to
> > another changing the filename in the process to include the original
> > folder names, but only if an actual file with extension exists in the
> > bottom child folder :
> >
> > Go from :
> >
> > Master Folder  ------> Sub Folder1 -----> Sub Sub Folder1 --->
> > filename.example
> >                          ------> Sub Folder2 -----> Sub Sub Folder1 --->
> > filename.example
> >                          ------> Sub Folder2 -----> Sub Sub Folder2 --->
> > filename.example
> >
> >
> > To:
> >
> >        /Var/MainFolder/Master_Sub1_SubSub1_filename.example
> >         /Var/MainFolder/Master_Sub2_SubSub1_filename.example
> >         /Var/MainFolder/Master_Sub2_SubSub2_filename.example   ....etc
> >
> >
> > Thanks
> > Andy
> >
> > _______________________________________________
> > Roundtable mailing list
> > Roundtable at muug.mb.ca
> > http://www.muug.mb.ca/mailman/listinfo/roundtable
>
>
>
> _______________________________________________
> Roundtable mailing list
> Roundtable at muug.mb.ca
> http://www.muug.mb.ca/mailman/listinfo/roundtable
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.muug.mb.ca/pipermail/roundtable/attachments/20100707/08d53f16/attachment-0001.html 


More information about the Roundtable mailing list