[RndTbl] script for file copy
Adam Thompson
athompso at athompso.net
Wed Jul 7 14:45:29 CDT 2010
Umm... I think I misunderstood the original question. You want to flatten a directory structure into a single directory while preserving a record of the original path encoded in the filename.
I think this would do what you want:
find "${SRC}" -type f -print | while read F1; do
F2=$( echo "${F1}" | tr '/' '_' )
mv "${F1}" "${F2}"
done
-Adam
> -----Original Message-----
> From: Adam Thompson [mailto:athompso at athompso.net]
> Sent: Wednesday, July 07, 2010 2:09 PM
> To: 'Continuation of Round Table discussion'
> Subject: RE: [RndTbl] script for file copy
>
> 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
More information about the Roundtable
mailing list