iphone - iOS - Check if file exists Dropbox Sync API iOS SDK -


i'm new ios development, , working on app support dropbox sync text files.

having followed tutorial on dropbox site i'm not able check if file exist.

as implemented:

nsstring *dropboxfileextension; switch ([[nsuserdefaults standarduserdefaults] integerforkey:kfileextension]) {     case txt:         dropboxfileextension = [nsstring stringwithformat:@"%@.txt", titlestring];         break;     case md:         dropboxfileextension = [nsstring stringwithformat:@"%@.md", titlestring];         break;     case markdown:         dropboxfileextension = [nsstring stringwithformat:@"%@.markdown", titlestring];         break;     default:         break; }  dbpath *newpath = [[dbpath root] childpath:[nsstring stringwithformat:@"%@", dropboxfileextension]]; dbfile *file = [[dbfilesystem sharedfilesystem] createfile:newpath error:nil]; [file writestring:self.note.contents error:nil]; 

if update contents, throws error file exists.

so how can check file exists , perform appropriate action overwriting file or updating file. thank you!

edit / working solution: logically, have check whether if file info exists using dbfileinfo class (1). if (1) true -> call openfile:error before writestring:error, else call createfile:error. suggested @rmaddy.

so...

dbpath *newpath = [[dbpath root] childpath:[nsstring stringwithformat:@"%@", dropboxfileextension]]; dberror *error = nil; dbfileinfo *info = [[dbfilesystem sharedfilesystem] fileinfoforpath:newpath error:&error]; if (info) {     // file exists     nslog(@"size %lli byte(s), modified dated %@", info.size, info.modifiedtime);     _file = [[dbfilesystem sharedfilesystem] openfile:newpath                                                 error:nil]; } else {     _file = [[dbfilesystem sharedfilesystem] createfile:newpath                                                   error:nil]; }  [_file writestring:self.note.contents error:nil]; 

try getting dbfileinfo path:

dberror *error = nil; dbfileinfo *info = [[dbfilesystem sharedfilesystem] fileinfoforpath:newpath error:&error]; if (info) {     // file exists } 

Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -