Re: Creating a series of sequenced files
Re: Creating a series of sequenced files
- Subject: Re: Creating a series of sequenced files
- From: Alex Zavatone <email@hidden>
- Date: Sat, 16 Apr 2016 17:56:29 -0400
The easy route is to use the file manager to see if the filename exists, then use NSString to separate the file name from the file extension, then use a string method creating an NSArray from the file name with items separated by the underscore, then take the last item in the array as an NSUinteger, increment by 1, make a new file name and if that file doesn’t exist, increment it by 1, keep doing that until it finds a file that hasn’t yet been created and then write the file.
On Apr 16, 2016, at 5:36 PM, Carl Hoefs <email@hidden> wrote:
> I have a daemon process that needs to generate a series of sequenced files (named sequentially, such as "file_01944576_1.dat", "file_01944576_2.dat", etc.) in the same directory. Does Cocoa provide a way to do this?
>
> NSFileManager's -createFileAtPath:contents:attributes: method states:
> "If a file already exists at path, this method overwrites the contents of that file..."
>
> I would hate to do this blindly, such as with fstat() in a loop, because there will potentially be many sequences, and each can grow to an arbitrary number. How do Finder and other OS X agents accomplish this?
> -Carl
>
>
> _______________________________________________
>
> Cocoa-dev mailing list (email@hidden)
>
> Please do not post admin requests or moderator comments to the list.
> Contact the moderators at cocoa-dev-admins(at)lists.apple.com
>
> Help/Unsubscribe/Update your Subscription:
>
> This email sent to email@hidden
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden