what is the perl code to delete a directory and what is perl code to rename a file or a directory??
Jun 12, 1999, 7:00 AM
User (68 posts)
Jun 12, 1999, 7:00 AM
Post #2 of 4
Views: 3396
Don't know if this works or directories...
This either...
------------------
webmaster@racedaze.com
Code:
rename("/path/old.name","/path/new.name");This either...
Code:
unlink ("/path/file_to_delete");------------------
webmaster@racedaze.com
Jun 12, 1999, 12:32 PM
Veteran (3111 posts)
Jun 12, 1999, 12:32 PM
Post #3 of 4
Views: 3396
From perldoc -f rename:
Changes the name of a file. Returns `1' for success, `0'
otherwise. Behavior of this function varies wildly
depending on your system implementation. For example, it
will usually not work across file system boundaries,
even though the system *mv* command sometimes
compensates for this. Other restrictions include whether
it works on directories, open files, or pre-existing
files. Check the perlport manpage and either the
rename(2) manpage or equivalent system documentation for
details.
From perldoc -f rmdir:
rmdir Deletes the directory specified by FILENAME if that
directory is empty. If it succeeds it returns TRUE,
otherwise it returns FALSE and sets `$!' (errno). If
FILENAME is omitted, uses `$_'.
And finally, from perldoc -f unlink:
unlink Deletes a list of files. Returns the number of files
successfully deleted.
$cnt = unlink 'a', 'b', 'c';
unlink @goners;
unlink <*.bak>;
Note: `unlink()' will not delete directories unless you
are superuser and the -U flag is supplied to Perl. Even
if these conditions are met, be warned that unlinking a
directory can inflict damage on your filesystem. Use
`rmdir()' instead.
If LIST is omitted, uses `$_'.
I hope this helps.
Quote:
rename OLDNAME,NEWNAME Changes the name of a file. Returns `1' for success, `0'
otherwise. Behavior of this function varies wildly
depending on your system implementation. For example, it
will usually not work across file system boundaries,
even though the system *mv* command sometimes
compensates for this. Other restrictions include whether
it works on directories, open files, or pre-existing
files. Check the perlport manpage and either the
rename(2) manpage or equivalent system documentation for
details.
From perldoc -f rmdir:
Quote:
rmdir FILENAME rmdir Deletes the directory specified by FILENAME if that
directory is empty. If it succeeds it returns TRUE,
otherwise it returns FALSE and sets `$!' (errno). If
FILENAME is omitted, uses `$_'.
And finally, from perldoc -f unlink:
Quote:
unlink LIST unlink Deletes a list of files. Returns the number of files
successfully deleted.
$cnt = unlink 'a', 'b', 'c';
unlink @goners;
unlink <*.bak>;
Note: `unlink()' will not delete directories unless you
are superuser and the -U flag is supplied to Perl. Even
if these conditions are met, be warned that unlinking a
directory can inflict damage on your filesystem. Use
`rmdir()' instead.
If LIST is omitted, uses `$_'.
I hope this helps.