Re: Creating a series of sequenced files

2016-04-16 Thread Jens Alfke
> On Apr 16, 2016, at 2:56 PM, Alex Zavatone wrote: > > The easy route is to use the file manager to see if the filename exists, then > […] keep doing that until it finds a file that hasn’t yet been created and > then write the file. This is generally considered a bad approach, because it’s s

Re: Creating a series of sequenced files

2016-04-16 Thread Quincey Morris
On Apr 16, 2016, at 15:29 , Carl Hoefs wrote: > > I have potentially n different ongoing sequences, so it seems like this > approach could end up hitting the filesystem really hard One enumeration per candidate directory shouldn’t be inefficient. That’s the order of magnitude of what the Find

Re: Creating a series of sequenced files

2016-04-16 Thread Carl Hoefs
> On Apr 16, 2016, at 3:20 PM, Quincey Morris > wrote: > > On Apr 16, 2016, at 15:10 , Carl Hoefs > wrote: >> >> But I'm concerned mainly with efficiency, as determining the next number in >> the naming sequence potentially can be extremely inefficient

Re: Creating a series of sequenced files

2016-04-16 Thread Quincey Morris
On Apr 16, 2016, at 15:10 , Carl Hoefs wrote: > > But I'm concerned mainly with efficiency, as determining the next number in > the naming sequence potentially can be extremely inefficient - trying 1000s > of times until the next available number every time a new file needs to be > written, an

Re: Creating a series of sequenced files

2016-04-16 Thread Quincey Morris
On Apr 16, 2016, at 14:36 , Carl Hoefs wrote: > > I have a daemon process that needs to generate a series of sequenced files Oh, sorry, I think I misunderstood the question. I thought you wanted to generate all the files at once. Alex’s interpretation sounds more plausible. If you’re looking t

Re: Creating a series of sequenced files

2016-04-16 Thread Carl Hoefs
> Not that I know of. But surely it’s only 2 lines of code, apart from error > checking and recovery? I'd love to see those 2 lines of code! :-) But I'm concerned mainly with efficiency, as determining the next number in the naming sequence potentially can be extremely inefficient - trying 100

Re: Creating a series of sequenced files

2016-04-16 Thread Quincey Morris
On Apr 16, 2016, at 14:36 , Carl Hoefs 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? Not that I know of. But

Re: Creating a series of sequenced files

2016-04-16 Thread Alex Zavatone
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 NSUinte

Creating a series of sequenced files

2016-04-16 Thread Carl Hoefs
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 fil