๐ฑ dreaming DiNO
[Kotlin] arrayList<CSVData> ์์ ํ์ผ ์ด๋ฆ์ด ๊ฐ์ผ๋ฉด ์ญ์ ํ๊ธฐ ๋ณธ๋ฌธ
Android/Android Studio
[Kotlin] arrayList<CSVData> ์์ ํ์ผ ์ด๋ฆ์ด ๊ฐ์ผ๋ฉด ์ญ์ ํ๊ธฐ
MK_____ 2023. 3. 8. 10:27์ฌ์ฉ์๊ฐ ์ ํํ Local data ๋ฅผ ์ญ์ ํ๋ ๊ณผ์
๋ฐฉ๋ฒ 1.
1. file name ๋ง ๋ค์ด๊ฐ ์๋ ์๋ก์ด arrayList<String>() ์ ๋ง๋ ๋ค.
2. arrayList.contains ๋ฅผ ํ์ฉํ๋ค.
private fun deleteLocalData(selectedList: ArrayList<CSVData>) {
BleDebugLog.i(logTag, "deleteLocalData-()")
val selectedNameList = ArrayList<String>()
selectedList.forEach {
selectedNameList.add(it.name)
}
val directory = File(path)
val files = directory.listFiles()
files?.forEach { file ->
if (file.isFile) {
val fileName = file.name
if (selectedNameList.contains(fileName)) {
val deleted = file.delete()
if (deleted) {
BleDebugLog.d(logTag, "$fileName deleted successfully")
} else {
BleDebugLog.d(logTag, "Failed to delete $fileName")
}
}
}
}
}
๋ฐฉ๋ฒ 2.
์๋ก์ด arrayList ๋ง๋ค๊ธฐ ์ซ์ด. ๊ท์ฐฎ์. ๐
๊ทธ๋ฅ ๋ฐ์ arrayList ์์ ๊ฐ์ ์ ๊ทผํด์ ๋น๊ตํ ์ ์์๊น?
์๋ค.. ์ฑ GPT ๋ง์๋ฆฌ
arrayList.any ๋ฅผ ํ์ฉํ๋ค.
private fun deleteLocalData(selectedList: ArrayList<CSVData>) {
BleDebugLog.i(logTag, "deleteLocalData-()")
val directory = File(path)
val files = directory.listFiles()
files?.forEach { file ->
if (file.isFile) {
val fileName = file.name
if (selectedList.any { it.name == fileName }) {
val deleted = file.delete()
if (deleted) {
BleDebugLog.d(logTag, "$fileName deleted successfully")
} else {
BleDebugLog.d(logTag, "Failed to delete $fileName")
}
}
}
}
}
'Android > Android Studio' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Kotlin] [์๋ฌํด๊ฒฐ] Retrofit (๋ ํธ๋กํ) post ๋ฐฉ์ Content-Type ํ์ธ (1) | 2023.03.16 |
---|---|
[Kotlin] arrayList์ ๋ด๊ธด ํน์ ๊ฐ ๋ง return ํ๊ธฐ -> .find() (0) | 2023.03.10 |
[Kotlin] Uri ๋ก๋ถํฐ Exif ๊ฐ ์ป๊ณ ์ค์ ๋ณ๊ฒฝํ๊ธฐ (0) | 2022.09.22 |
[Android Studio] ๋ผ์ด๋ธ๋ฌ๋ฆฌ .aar ๊ต์ฒด (0) | 2022.09.22 |
[Kotlin] Uri <-> String (0) | 2022.08.26 |