[futurebasic] RE: [FB] Rename a file using CFURLRef

Message: < previous - next > : Reply : Subscribe : Cleanse
Home   : June 2013 : Group Archive : Group : All Groups

From: "Edwards, Waverly" <Waverly.Edwards@...>
Date: Fri, 28 Jun 2013 13:18:00 -0500
Ah, I see how it works.
Good idea, checking the extension, since it would be the last component.
Looking forward to making use of it.


W.


-----Original Message-----
From: futurebasic@... [mailto:futurebasic@...] On Behalf Of Ken Shmidheiser
Sent: Friday, June 28, 2013 9:53 AM
To: futurebasic@...
Subject: RE: [FB] Rename a file using CFURLRef

Here's a little contribution.

Ken


compile as "Objective-C"
include "ConsoleWindow"

BeginCDeclaration
CFStringRef RenameFile( CFStringRef filePath, CFStringRef newFileName );
EndC

BeginCFunction
CFStringRef RenameFile( CFStringRef filePath, CFStringRef newFileName ) {
NSString *destPath;
NSFileManager *fileMgr = [NSFileManager defaultManager];
NSString* extension = [(NSString*)filePath pathExtension];

if ( [extension length] > 0 )
{
  destPath = [NSString stringWithFormat:@"%@/%@.%@", [(NSString *)filePath stringByDeletingLastPathComponent], (NSString *)newFileName, extension];
}
else
{
  destPath = [NSString stringWithFormat:@"%@/%@", [(NSString *)filePath stringByDeletingLastPathComponent], (NSString *)newFileName];
}
[fileMgr movePath:(NSString *)filePath toPath:destPath handler:nil];
return (CFStringRef)destPath;
}
EndC
toolbox fn RenameFile( CFStringRef fileURL, CFStringRef newFileName ) = CFStringRef

dim as CFURLRef    path
dim as CFStringRef result

if ( files$( _CFURLRefOpen,,, @path ) )
result = fn RenameFile( fn CFURLCopyFileSystemPath( path, _kCFURLPOSIXPathStyle ), @"Renamed File" )
end if

fn HIViewSetText( sConsoleHITextView, result )


--
To unsubscribe, send ANY message to: futurebasic-unsubscribe@...
To access the list archives, go to:  http://freegroups.net/groups/futurebasic/