[Unity][C#] 지정된 폴더 에서 폴더 목록 가져오기

2020. 4. 6. 16:59개발 달리기/Unity 개발달리기

안녕하세요. 달리는애아빠입니다.



이번에 필요한 기능중에 지정한 폴더내에서 이미 생성되어있는 폴더들의 이름을 구하기위한 알고리즘입니다.


1
2
3
4
5
6
7
8
9
10
11
private string GamePath = System.Environment.CurrentDirectory + "\\Game";
 
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(GamePath);
 
foreach (System.IO.DirectoryInfo Dir in di.GetDirectories())
{
     string FileDirectory = Dir.Name;
     m_Directory.Add(FileDirectory);
}
 
 
cs




지정한 폴더내의 폴더들의 이름을 가져오는 코드입니다.


결과





이제 안쪽의 system.IO.DirectoryInfo 의 기능으로 응용하자면



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
private string GamePath = System.Environment.CurrentDirectory + "\\Game";
 
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(GamePath);
 
foreach (System.IO.DirectoryInfo Dir in di.GetDirectories())
{
      string Directory = Dir.Name;            
      string FullFileDirectory = Dir.FullName;
      
 
      Debug.Log("Directory = " + Directory);
      Debug.Log("FullFileDirectory = " + FullFileDirectory);     
 
}
 
 
cs



Full Path 도 충분히 가져올수 있습니다.


결과







지정폴더 안에 - 폴더명 가져오는 알고리즘 활용 잘하시길 바랍니다.



감사합니다.







미약하게나마 유용한 정보가 되었다면 구독 공감 버튼은 작성자에게 큰 힘이 됩니다. 감사합니다 ^^