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).<div>
<br></div><div>Kevin<br><br><div class="gmail_quote">On Wed, Jul 7, 2010 at 2:09 PM, Adam Thompson <span dir="ltr"><<a href="mailto:athompso@athompso.net">athompso@athompso.net</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
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.<br>
I would look at "rsync", used in local mode, use something like<br>
<br>
$ rsync -a --existing SRCDIR DSTDIR<br>
<br>
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.<br>
<br>
The best non-recursive technique I can think of would be something like:<br>
#!/bin/sh<br>
SRC="$1"<br>
DST="$2"<br>
T1=$(mktemp)<br>
T2=$(mktemp)<br>
find "${SRC}" -type f -print | sed -e "s/^${SRC}//" | sort > "${T1}"<br>
find "${DST}" -type f -print | sed -e "s/^${DST}//" | sort > "${T1}"<br>
comm -12 "$T1" "$T2" | while read F ; do<br>
cp "${SRCDIR}${F}" "${DSTDIR}${F}"<br>
done<br>
<font color="#888888"><br>
-Adam<br>
</font><div><div></div><div class="h5"><br>
> -----Original Message-----<br>
> From: <a href="mailto:roundtable-bounces@muug.mb.ca">roundtable-bounces@muug.mb.ca</a> [mailto:<a href="mailto:roundtable-">roundtable-</a><br>
> <a href="mailto:bounces@muug.mb.ca">bounces@muug.mb.ca</a>] On Behalf Of VE4ER / Andy<br>
> Sent: Wednesday, July 07, 2010 12:10 PM<br>
> To: MUUG Roundtable<br>
> Subject: [RndTbl] script for file copy<br>
><br>
> Can anybody suggest a script to copy files from one directory structure to<br>
> another changing the filename in the process to include the original<br>
> folder names, but only if an actual file with extension exists in the<br>
> bottom child folder :<br>
><br>
> Go from :<br>
><br>
> Master Folder ------> Sub Folder1 -----> Sub Sub Folder1 ---><br>
> filename.example<br>
> ------> Sub Folder2 -----> Sub Sub Folder1 ---><br>
> filename.example<br>
> ------> Sub Folder2 -----> Sub Sub Folder2 ---><br>
> filename.example<br>
><br>
><br>
> To:<br>
><br>
> /Var/MainFolder/Master_Sub1_SubSub1_filename.example<br>
> /Var/MainFolder/Master_Sub2_SubSub1_filename.example<br>
> /Var/MainFolder/Master_Sub2_SubSub2_filename.example ....etc<br>
><br>
><br>
> Thanks<br>
> Andy<br>
><br>
> _______________________________________________<br>
> Roundtable mailing list<br>
> <a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
> <a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
<br>
<br>
<br>
_______________________________________________<br>
Roundtable mailing list<br>
<a href="mailto:Roundtable@muug.mb.ca">Roundtable@muug.mb.ca</a><br>
<a href="http://www.muug.mb.ca/mailman/listinfo/roundtable" target="_blank">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br>
</div></div></blockquote></div><br></div>