# 애플 [Apple]/macOS
[🍎 macOS] 파일 공유 폴더 목록 가져오는 방법 (How to get list of shared folders)
cy_mos
2023. 10. 31. 21:45
반응형
macOS 환경에서 파일 공유 폴더 목록을 가져오는 방법은 아래와 같습니다.
※ Xcode 프로젝트에서 Frameworks, Libraries, and Embedded Content 항목에 OpenDirectory.framework를 추가하여야 사용이 가능합니다.
🗂️ [Objective-C] 파일 공유 폴더 목록가져오기
더보기
#import <OpenDirectory/OpenDirectory.h>
@autoreleasepool {
NSMutableDictionary * dictionary = [NSMutableDictionary new];
NSError * error = NULL;
ODNode * localNode = [ODNode nodeWithSession: ODSession.defaultSession
type: ODNodeType(kODNodeTypeLocalNodes)
error: &error];
if (error != NULL) {
NSLog(@"[ERROR] Could't Getting Local Node Error: %@", error.description);
return NULL;
}
error = NULL;
ODQuery * query = [ODQuery queryWithNode: localNode
forRecordTypes: kODRecordTypeSharePoints
attribute: NULL
matchType: ODMatchType(kODMatchAny)
queryValues: NULL
returnAttributes: kODAttributeTypeAllAttributes
maximumResults: -1
error: &error];
if (error != NULL) {
NSLog(@"[ERROR] Could't Creating Query Error: %@", error.description);
return NULL;
}
error = NULL;
NSArray * result = [query resultsAllowingPartial: false
error: &error];
if (error != NULL) {
NSLog(@"[ERROR] Could't Getting Query Result: %@", error.description);
return NULL;
}
for (ODRecord * recode in result) {
error = NULL;
NSString * sharePointName = [recode valuesForAttribute: kODAttributeTypeRecordName
error: &error].firstObject;
if (error != NULL) {
NSLog(@"[ERROR] Coudl't Getting SharePointName: %@", error.description);
continue;
}
error = NULL;
NSString * sharePointPath = [recode valuesForAttribute: @"dsAttrTypeNative:directory_path"
error: &error].firstObject;
if (error != NULL) {
NSLog(@"[ERROR] Could't Getting SharePointPath: %@", error.description);
continue;
}
NSArray * object = [NSArray arrayWithObjects: sharePointName, sharePointPath, nil];
[dictionary setObject: object
forKey: sharePointPath];
}
return dictionary;
}
🗂️ [Swift] 파일 공유 폴더 목록가져오기
더보기
import OpenDirectory
let session = ODSession.default()
let node = try ODNode(session: session, type: ODNodeType(kODNodeTypeLocalNodes))
let query = try ODQuery(
node: node,
forRecordTypes: kODRecordTypeSharePoints,
attribute: nil,
matchType: ODMatchType(kODMatchAny),
queryValues: nil,
returnAttributes: kODAttributeTypeAllAttributes,
maximumResults: -1
)
let results = try query.resultsAllowingPartial(false) as! [ODRecord]
for r in results {
let v1 = try r.values(forAttribute: kODAttributeTypeRecordName)
print(v1)
let v2 = try r.values(forAttribute: "dsAttrTypeNative:directory_path")
print(v2)
print("--")
}
🚀 REFERENCE
반응형