Re: Renaming a Directory

From: Date: Wed, 09 Sep 2009 13:26:46 +0000
Subject: Re: Renaming a Directory
References: 1 2 3  Groups: php.general 
Request: Send a blank email to php-general+get-297812@lists.php.net to get a copy of this message
On Wed, Sep 09, 2009 at 12:11:14AM -0400, Eddie Drapkin wrote: > On Wed, Sep 9, 2009 at 12:08 AM, Paul M Foster<paulf@quillandmouse.com> wrote: > > On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote: > > > >> How can I rename a directory with files in it?  The rename function > >> gives me a "directory not empty" error.  I know I could do it be > >> creating the directory, moving the files, and then deleting the old > >> one.  Is there an easier way? > > > > It sounds like, underneath, rename() is creating a new directory and > > then attempting to delete the old one, ignoring the files in the > > original directory. In which case, you'll have to do it the long way-- > > create a new directory, move the files, then delete the old directory.. > > > > Oddly enough, I can't find a *nix command which will actually rename a > > directory. The man pages for mv, rename and such all refer only to > > files, not directories. > > > > mv renames directories fine: > $ mkdir bar > $ touch bar/randomfile > $ mv bar foo > $ ls foo > randomfile > > :) I would have thought so, but the man pages didn't mention it. I haven't use mv in ages. Makes sense that it would work, though. Moving/renaming a file would just change the name, not the inode number, which is the real key to *nix file systems. Paul -- Paul M. Foster

« previous php.general (#297812) next »