Re: Rename nested folders
Re: Rename nested folders
- Subject: Re: Rename nested folders
- From: "Mark J. Reed" <email@hidden>
- Date: Wed, 21 May 2008 22:30:11 -0400
On Wed, May 21, 2008 at 9:11 AM, Stranathan, Dan
<email@hidden> wrote:
> His problem is that the sub folders have forward slashes ("/") in them, which need to be removed and replaced with
> a dash.
That's an odd way of putting that. The slashes are folder delimiters;
so he's getting a zip file containing a folder named Manuscripts with
a subfolder named 2008 with a subfolder named 091066, and you want to
instead have a top-level folder named Manuscripts-2008-091066. So
you're just flattening the archive to a single level of folders, yes?
> (The files inside the folders are fine, its only the folders that have slashes in their names)
Again, you're drawing an arbitrary division that is not there
naturally. You might as well say that there's a folder named
"Manuscripts/2008" with a bunch of files named e.g. "091066/"
something that need to be cleaned up. Or even, the folder name is
just "Manuscripts", which would be fine, but all the files are named
"2008/091066/something" with those annoying slashes! :)
> As a final step, Id like the folders to be re-zipped back into a single .zip archive again (without any MACOSX or .DS_Store files preferably. I have noticed that the OS X GUI Archive Utility creates these annoying files, but the command line "zip -r" command does not create them)
Those files are a lot less annoying than finding out too late that
your ZIP archive is totally free of resource forks. :) But yes, zip
-r doesn't include them, and even when it becomes smart enough to
include them (which the Leopard man page indicates it is, but it's not
really), it will have an option (the one on the Leopard man page, I
presume) to leave them out. The other option is to use ditto, which
will let you include them or not, and gives you a couple options as
far as what the names are.
> Any advice, samples or suggestions are appreciated.
I don't know if you can convince the archive utility to leave out
resource forks, even from AS... below is a shellish solution; a more
AppleScripty one may come from another quarter. Oh, and it's
interactive as written, but should be easy to turn into a droplet if
you want.
This assumes that the only things in the ZIP file that you care about
are the actual files, not any other empty folders that might be about.
sset zipFile to choose file with prompt "Select the ZIP file to fix"
set zipPath to quoted form of POSIX path of zipFile
do shell script "z=" & zipPath & "; tmpdir=/tmp/zipfix$$; mkdir
$tmpdir && cd $tmpdir && unzip -qq \"$z\" && find * ! -type d | while
read f; do d=\"$(dirname \"$f\")\"; n=\"$(echo \"$d\" | tr / -)\"; if
[ \"$n\" != \"$d\" ]; then mv \"$d\" \"$n\"; fi; done; find . -type d
-depth -print0 | xargs -0 rmdir 2>/dev/null; mv \"$z\" \"$z\".orig;
zip -q -r \"$z\" *; cd - >/dev/null && rm -rf $tmpdir"
--
Mark J. Reed <email@hidden>
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden