Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
General
GeneralPortable MacsHardwareNetworking
Applications
Mac ApplicationsEudoraFirefox / MozillaInternet ExplorerOutlook ExpressMS OfficeEntourageExcelPowerPointWordVirtual PCMedia PlayerOther MS Products
Programming
Mac ProgrammingCodeWarriorPerl
Country Specific
Australian Mac GroupUK Mac Group

Mac Forum / Programming / Perl / January 2006



Tip: Looking for answers? Try searching our database.

System "rename" command

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
John Horner - 08 Jan 2006 01:25 GMT
I was trying to do something involving renaming files the other day and
I wrote:

  system("rename $originalname $newname");

and got an error. I figured out in the end I was getting confused --
perl has a rename function and if I want to do the system way, I need
"mv" instead.

But when I do "man rename" I get a manpage. So how come in Panther I
don't have a system rename command but I do have a manpage for it?

Supplementary question. If you were moving, copying and renaming files,
would you use File::Copy instead of cp and mv?
John Delacour - 08 Jan 2006 01:52 GMT
>Supplementary question. If you were moving, copying and renaming
>files, would you use File::Copy instead of cp and mv?

You should first consider ditto if there is any chance your files
contain valuable resource forks.

%  ditto --rsrc ...

JD
Dominic Dunlop - 08 Jan 2006 17:41 GMT
>> Supplementary question. If you were moving, copying and renaming  
>> files, would you use File::Copy instead of cp and mv?

Because by doing so you will make your script portable to Windows,  
VMS, z/OS, Symbian ... However, I just checked, and the module does  
not handle Mac OS X resource forks, so

> You should first consider ditto if there is any chance your files  
> contain valuable resource forks.
>
> %  ditto --rsrc ...

No need to bother with this Mac OS X-specific wrinkle if you're  
running Tiger -- from <http://www.apple.com/macosx/features/unix/>:

"Use command-line commands safely on HFS+ files. Utilities such as  
cp, mv, tar, rsync now use the same standard APIs as Spotlight and  
access control lists to handle resource forks properly."

So use File::Copy for portability across operating systems (provided  
you know you'll never meet a resource fork on Mac OS), ditto  for  
portability across Mac OS X versions, or  mv  for portability across  
UNIX versions (including Mac OS X 10.4, but not lower). Phew.

Looking at the POD, I find that

"File::Copy also provides the "syscopy" routine, which copies the  
file specified in the first parameter to the file specified in the  
second parameter, preserving OS-specific attributes and file structure."

Umm, no it doesn't on Mac OS X. However

"On Mac OS (Classic), "syscopy" calls "Mac::MoreFiles::FSpFileCopy",  
if available."

As Tiger makes Mac::MoreFiles::FSpFileCopy available (previous  
releases don't), and the function does indeed copy a file including  
its resource fork (although it lost the icon for the file I'm testing  
with -- maybe that's a Finder thing), I consider it a bug that  
File::Copy does not use it if it can on Mac OS X. With your  
permission, I'll raise a bug report.
Signature

Dominic Dunlop

grassie@att.net - 08 Jan 2006 01:56 GMT
From: John Horner <bounce@johnhorner.nu>

> But when I do "man rename" I get a manpage. So how come in Panther I
> don't have a system rename command but I do have a manpage for it?

That appears to be a Section 2 manpage (system call, not a command).
Commands are in Section 1.  Try:

   man 1 rename    

(no joy)

Paul
grassie@perl.com
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.