Re: Autocreate Directory with a new name

From: Lew Pitcher (lpitcher_at_sympatico.ca)
Date: 05/26/05


Date: Wed, 25 May 2005 19:35:12 -0400


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

binary-nomad@hotmail.com wrote:
> How do I create a directory, and if it fails, if a directory with that
> name already exists there, retry with a different name?

You've received quite a bit of advice and discussion on this.

I'd like to suggest a different approach.

Why not create a deliberately unique-named directory (say, with something like
tempfile(1) or mktemp(1) ), and then try to rename it to the target name?

If the rename fails, then you have the end result of your "retry with a
different name" requirement. OTOH, if the rename succeeds, then you have the
end result of your "create a directory" requirement.

- --
Lew Pitcher

Master Codewright & JOAT-in-training | GPG public key available on request
Registered Linux User #112576 (http://counter.li.org/)
Slackware - Because I know what I'm doing.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (GNU/Linux)

iD8DBQFClQuwagVFX4UWr64RAkY6AJ9fcPP7nb9UEheBW4CpUXuGg5E0egCglRHm
LmpU7sTvekpOdUXynmbUoWY=
=Y6Gs
-----END PGP SIGNATURE-----



Relevant Pages