cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Back again with another edition of 'How we use Dropbox', so find out how Emma uses to-do lists to get it all done here!

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

How can I check to see if a file already exists with Dropbox Sync iOS API?

How can I check to see if a file already exists with Dropbox Sync iOS API?

Matthew W.8
New member | Level 1

I would like my app to test whether there is already a file at certain path before trying to upload a file to that path.

How could I do that?

I have an array called sortedFiles. Then I have

int i = 0;

    do{

        NSString *fileName = [NSString stringWithFormat:@"Pace audio/%@", [[sortedFiles objectAtIndex:i] objectForKey: @"path"]];
        DBPath *newPath = [[DBPath root]childPath:fileName];
        DBFile *file = [[DBFilesystem sharedFilesystem] createFile:newPath error:nil];

        if ( ) //and some sort of test here to see if the file already exists at this path
            [file writeContentsOfFile:fileName shouldSteal:NO error:nil];
        else {
            NSLog(@"File already exists");
        }

        NSLog(@"The number is %d", i);
        i++;

    }
    while (i < sortedFiles.count);

I've been searching the documentation and I can't think of a way to do this. At the moment, I just get an error saying a file already exists, so at least the file isn't being overwritten.

Ideas?

Thanks.

2 Replies 2

Re: How can I check to see if a file already exists with Dropbox Sync iOS API?

Greg-DB
Dropboxer

You can use DBFilesystem.fileInfoForPath:

https://www.dropbox.com/developers/sync/docs/ios#DBFilesystem.fileInfoForPath:error:

You probably want to do that before you do createFile though.

Re: How can I check to see if a file already exists with Dropbox Sync iOS API?

Matthew W.8
New member | Level 1

Thanks and good catch. That worked

Poll
We love to learn from the educators who use Dropbox. Whether you teach kids, teens, adults or a combination of all three, we want to know what apps and integrations you use with Dropbox to help with teaching. Which of the ones below is your favorite, or most used tool?
Who's talking

Top contributors to this post

  • User avatar
    Matthew W.8 New member | Level 1
  • User avatar
    Greg-DB Dropboxer
What do Dropbox user levels mean?
Need more support?