i need detect when usb drive e.g. office23, mounted in os x , search file eg. jan.txt inside drive , copy app bundle.
i using following method find if volume mounted or not:
nsfilemanager *filemanager = [nsfilemanager defaultmanager]; nserror *error = error; nsarray *keys = @[nsurlvolumenamekey, nsurlvolumeisremovablekey, nsurlvolumeisejectablekey]; nsarray *volumeurl = [filemanager mountedvolumeurlsincludingresourcevaluesforkeys:keys options:nsvolumeenumerationproducefilereferenceurls]; (nsurl *url in volumeurl) { nslog(@"url %@", url); }
result: file:///.file/id=6571367.2/
how can nsurl of file inside volume?
edit 1:
nsarray *keys = [nsarray arraywithobjects:nsurlvolumenamekey, nsurlvolumeisremovablekey, nil]; nsarray *urls = [[nsfilemanager defaultmanager] mountedvolumeurlsincludingresourcevaluesforkeys:keys options:0]; nsurl *officedriveurl; (nsurl *url in urls) { nserror *error; nsnumber *isremovable; nsstring *volumename; [url getresourcevalue:&isremovable forkey:nsurlvolumeisremovablekey error:&error]; if ([isremovable boolvalue]) { [url getresourcevalue:&volumename forkey:nsurlvolumenamekey error:&error]; if ([[url absolutestring] containsstring:@"office"]) { officedriveurl = url; } } } nsurl *fullurl = [officedriveurl urlbyappendingpathcomponent:@"documents/my file2.txt"]; if ([[nsfilemanager defaultmanager]fileexistsatpath:[fullurl absolutestring]]) { nslog(@"yes file exist %@", fullurl); }
still, filemanager cannot find url.
the fullurl is: file:///volumes/office/documents/my%file2.txt
when check through finder or nsfilemanager, not not work, path correct.
i don't know why filemanager did not find file using [nsurl absolutestring] method, when removed file:// file:///volumes/office/documents/my%file2.txt , modified %20, got introduced (my%20file2,txt), worked.
Comments
Post a Comment