반응형
iOS 16.1, Xcode 14.2, Swift 5, UIKit 환경에서 진행했습니다.
폴더 생성 코드
let documentURL = FileManager.urls(for: .documentDirectory, in: .userDomainMask).first!
let directoryURL = documentURL.appendPathComponent("folder")
do {
try fileManager.createDirectory(atPath: directoryURL.path, withIntermediateDirectories: false, attributes: nil)
} catch let e as NSError {
print(e.localizedDescription)
}
파일 삭제 코드
let fileURL = ...
if fileManager.fileExists(atPath: fileURL.path) {
try? fileManager.removeItem(atPath: fileURL.path)
}
파일 복제 코드
try FileManager.default.moveItem(atPath: url.path, toPath: tempURL.path)
파일명 가져오는 코드
let fileName = fileURL.lastPathComponent
반응형
'iOS > 코드조각' 카테고리의 다른 글
[iOS, Swift] Data 용량 크기 구하기 (0) | 2023.03.06 |
---|---|
[iOS, Swift] DocumentPicker로 선택한 파일 저장하기 (0) | 2023.03.05 |
[iOS, Swift] hugging priorty 및 CompressionResistancePriority 수정(programmatic) (0) | 2023.03.03 |
[iOS, Swift] TableView의 특정 셀 가져오기(indexPath) (0) | 2023.03.01 |
[iOS, Swift] 이미지뷰에 이미지 넣기(인터넷 url 주소) (0) | 2023.02.28 |