cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to learn some quick and useful tips to make your day easier? Check out how Calvin uses Replay to get feedback from other teams at Dropbox 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

Greg-DB
Dropbox Staff

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.

Matthew W.8
New member | Level 1

Thanks and good catch. That worked

Need more support?
Who's talking

Top contributors to this post

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