Renaming a Directory
am 08.09.2009 23:39:43 von Floyd Resler
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?
Thanks!
Floyd
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 08.09.2009 23:46:50 von Eddie Drapkin
On Tue, Sep 8, 2009 at 5:39 PM, 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 ther=
e an
> easier way?
>
> Thanks!
> Floyd
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
Is there something wrong with `system("mv $oldName $newName");` ?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 06:08:21 von Paul M Foster
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.
Paul
--
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 06:11:14 von Eddie Drapkin
On Wed, Sep 9, 2009 at 12:08 AM, Paul M Foster wro=
te:
> 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.
>
> Paul
>
> --
> Paul M. Foster
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
mv renames directories fine:
$ mkdir bar
$ touch bar/randomfile
$ mv bar foo
$ ls foo
randomfile
:)
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 10:54:22 von Ashley Sheridan
On Wed, 2009-09-09 at 00:08 -0400, Paul M Foster 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.
>
> Paul
>
> --
> Paul M. Foster
>
That's because in *nix, everything is a file. Directories, devices, all
have file interfaces.
Thanks,
Ash
http://www.ashleysheridan.co.uk
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 14:09:00 von Floyd Resler
Nope, nothing wrong with that at all. Just didn't think of it!
Thanks!
Floyd
On Sep 8, 2009, at 5:46 PM, Eddie Drapkin wrote:
> On Tue, Sep 8, 2009 at 5:39 PM, 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?
>>
>> Thanks!
>> Floyd
>>
>>
>> --
>> PHP General Mailing List (http://www.php.net/)
>> To unsubscribe, visit: http://www.php.net/unsub.php
>>
>>
>
> Is there something wrong with `system("mv $oldName $newName");` ?
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 15:26:46 von Paul M Foster
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=
wrote:
> > On Tue, Sep 08, 2009 at 05:39:43PM -0400, Floyd Resler wrote:
> >
> >> How can I rename a directory with files in it? =A0The rename functio=
n
> >> gives me a "directory not empty" error. =A0I know I could do it be
> >> creating the directory, moving the files, and then deleting the old
> >> one. =A0Is 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.
> >
>=20
> mv renames directories fine:
> $ mkdir bar
> $ touch bar/randomfile
> $ mv bar foo
> $ ls foo
> randomfile
>=20
> :)
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
--=20
Paul M. Foster
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 16:10:42 von Tom Worster
On 9/9/09 12:08 AM, "Paul M Foster" 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.
really?
the test below seems to show that php rename() is happy to rename
directories that are not empty. it even renames ones that contain files that
it neither owns nor has any permissions for. that suggests it is just
changing the name of the directory.
so the error message floyd reported is still a mystery to me, assuming
/bin/mv worked for the same old and new directories where php rename()
failed.
$ mkdir wwwdir
$ sudo chown www:www wwwdir
$ cd wwwdir
$ sudo -u www mkdir testdir
$ sudo -u www touch testdir/foo testdir/bar
$ sudo -u www php -r "echo rename('testdir','dirtest');"
1$ ls -la dirtest
total 0
drwxr-xr-x 4 _www _www 136 Sep 9 09:57 .
drwxr-xr-x 3 _www _www 102 Sep 9 09:57 ..
-rw-r--r-- 1 _www _www 0 Sep 9 09:57 bar
-rw-r--r-- 1 _www _www 0 Sep 9 09:57 foo
$ sudo -u www chmod 000 dirtest/foo
$ sudo -u www php -r "echo rename('dirtest','testdir');"
1$ ls -la testdir
total 0
drwxr-xr-x 4 _www _www 136 Sep 9 09:57 .
drwxr-xr-x 3 _www _www 102 Sep 9 09:57 ..
-rw-r--r-- 1 _www _www 0 Sep 9 09:57 bar
---------- 1 _www _www 0 Sep 9 09:57 foo
$ sudo chown root:wheel testdir/foo
$ sudo -u www -u www php -r "echo rename('testdir','dirtest');"
1$ ls -la dirtest
total 0
drwxr-xr-x 4 _www _www 136 Sep 9 09:57 .
drwxr-xr-x 3 _www _www 102 Sep 9 09:57 ..
-rw-r--r-- 1 _www _www 0 Sep 9 09:57 bar
---------- 1 root wheel 0 Sep 9 09:57 foo
$ php -v
PHP 5.2.8 (cli) (built: Feb 5 2009 21:21:13)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
$ uname -v
Darwin Kernel Version 9.8.0: Wed Jul 15 16:55:01 PDT 2009;
root:xnu-1228.15.4~1/RELEASE_I386
$
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Re: Renaming a Directory
am 09.09.2009 16:13:22 von Lupus Michaelis
Paul M Foster a écrit :
> 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.
Ashley said it, a directory is a file. But more, when you do a mv on
a file, it don't rename. If the target is in the same filesystem, mv do
a hard link on the source file, then unlink the original name. If you
move accross filesystem, mv do a copy of the directory.
If you don't believe me, get the source.
--
Mickaël Wolff aka Lupus Michaelis
http://lupusmic.org
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php