using System; using System.Collections.Generic; using System.Linq; using System.Text; using Android.App; using Android.Content; using Android.OS; using Android.Runtime; using Android.Views; using Android.Widget; using Java.IO; namespace CommonLib { class FileListManager { const int INCREASE_UNIT = 10; public static string[] Get(string[] filterArray, string strPath = "") { int nFilePos = 0; if(string.IsNullOrEmpty(strPath)==true) strPath = Android.OS.Environment.ExternalStorageDirectory.AbsolutePath; string[] fileArray = new string[INCREASE_UNIT]; Array.Clear(fileArray, 0, INCREASE_UNIT); Get(strPath, filterArray, ref fileArray, ref nFilePos); string[] fileArrayBuff = new string[nFilePos]; for(int i = 0; i < nFilePos; i++) fileArrayBuff[i] = fileArray[i]; return fileArrayBuff; } public static string[] Get(string strFilter, string strPath = "") { string[] filterArray = new string[1]; filterArray[0] = strFilter; return Get(filterArray, strPath); } public static string[] GetAdjustFileNames(string[] fileArray, int nLength = 20) { string[] fileNames = new string[fileArray.Length]; int nPos; for (int i = 0; i < fileArray.Length; i++) { nPos = fileArray[i].LastIndexOf("/"); //µð·ºÅ丮 Á¦°Å if (nPos >= 0) fileNames[i] = fileArray[i].Substring(nPos + 1); else fileNames[i] = fileArray[i]; nPos = fileNames[i].LastIndexOf("."); //È®ÀåÀÚ Á¦°Å if (nPos >= 0) fileNames[i] = fileNames[i].Substring(0, nPos); nPos = fileNames[i].Length; //nLengthº¸´Ù ±æ¸é Àß¶ó³¿ if (nLength <= 0) continue; if (nPos <= nLength - 3) continue; nPos = nLength - 3; fileNames[i] = fileNames[i].Substring(0, nPos); fileNames[i] += "..."; } return fileNames; } static void SetFile(ref string[] fileArray, ref int nFilePos, string strFile) { if (nFilePos >= fileArray.Length) { int nSize = fileArray.Length; Array.Resize(ref fileArray, nSize + 100); Array.Clear(fileArray, nSize, INCREASE_UNIT); } fileArray[nFilePos++] = strFile; } static void Get(string strPath, string[] filterArray, ref string[] fileArray, ref int nFilePos) { try { File home = new File(strPath); // homeÀ¸·Î sdÄ«µåÀÇ root¸¦ ÁöÁ¤ÇÕ´Ï´Ù. File file = null; bool bStatus; string strPathFile; string[] files = home.List(); if (files == null) return; for (int i = 0; i < files.Length; i++) { strPathFile = strPath + "/" + files[i]; file = new File(strPathFile); if (file.IsDirectory == true) { Get(strPathFile, filterArray, ref fileArray, ref nFilePos); } else { if (files[i].Length <= 4) continue; string strExt = files[i].Substring(files[i].Length - 4); bStatus = false; for (int j = 0; j < filterArray.Length; j++) { if (strExt == filterArray[j]) { bStatus = true; break; } } if(bStatus==true) SetFile(ref fileArray, ref nFilePos, strPathFile); } } } catch (Exception e) { e.ToString(); } } } }