Last active
August 3, 2020 10:20
-
-
Save IngIeoAndSpare/711a2cda332187b980c2d071063b93b4 to your computer and use it in GitHub Desktop.
example file list
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.IO; | |
// list init for file info dto | |
List<TargetFileInfoDTO> fileInfoList = new List<TargetFileInfoDTO>(); | |
// root file path (dds, jpg file root path) | |
string ROOT_FILE_PATH = @"FILE_PATH"; | |
// search option dict | |
string SEARCH_FILE_FORMAT = "jpg"; | |
Dictionary<string, string> searchOptionDict = new Dictionary<string, string>() { | |
{ "jpg" , "*.jpg" }, | |
{ "dds" , "*.dds" } | |
}; | |
// ienumerator init | |
IEnumerator<FileInfo> jpgFile = | |
new DirectoryInfo(ROOT_FILE_PATH).EnumerateDirectories("*", SearchOption.TopDirectoryOnly).GetEnumerator(). | |
Current.EnumerateFiles(searchOptionDict[SEARCH_FILE_FORMAT], SearchOption.AllDirectories).GetEnumerator(); | |
// get file (one by one) ---> end | |
while (jpgFile.MoveNext()) { | |
// dto init | |
TargetFileInfoDTO fileInfoDTO = new TargetFileInfoDTO(); | |
fileInfoDTO.filePath = jpgFile.Current.FullName; | |
fileInfoDTO.fileName = jpgFile.Current.Name.Replace( | |
string.Format(".{0}", SEARCH_FILE_FORMAT), "" | |
); | |
fileInfoDTO.fileFormat = SEARCH_FILE_FORMAT | |
// add file info dto | |
fileInfoList.Add(fileInfoDTO); | |
} | |
// dto example | |
public class TargetFileInfoDTO | |
{ | |
public string filePath { get; set; } | |
public string fileName { get; set; } | |
public string fileFormat { get; set; } | |
} | |
// get file list... | |
foreach(TargetFileInfoDTO fileInfoDTO in fileInfoList) { | |
fileInfoDTO.filePath | |
fileInfoDTO.fileName | |
fileInfoDTO.fileFormat | |
// todo some work. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment