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 <newsli...@autonomy.caltech.edu> 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 (Cocoa-dev@lists.apple.com) > > 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: > https://lists.apple.com/mailman/options/cocoa-dev/zav%40mac.com > > This email sent to z...@mac.com _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) 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: https://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to arch...@mail-archive.com