상세 컨텐츠

본문 제목

[Unity] 유니티 파일 생성, 삭제, 체크 함수 관련

게임엔진관련/유니티 엔진

by AlrepondTech 2020. 1. 14. 11:12

본문

반응형

 

 

 

 

=================================

=================================

=================================

 

 

 

 

 

 

 

 

출처: https://green4you.tistory.com/23

 

파일의 생성과 삭제 그리고 파일 유무 체크 시에 사용하는 함수는

 

using System.IO 네임스페이스 안에 정의 되어 있다.

 

인자값으로 파일의 이름을 포함한 경로를 넣어주면 된다.

 

 

생성

System.IO.File.Create ( string FilePath );

 

 

삭제

System.IO.File.Delete(  string FilePath  );

 

 

체크

System.IO.File.Exists(  string FilePath  );

 

중요

위 함수를 사용한 후에 파일 입출력등 파일 관련 작업을 하게 되는 경우 정상적으로 작동되지 않는 경우가 발생한다.

 

확인결과  파일사용후 close 시켜주지 않아서 발생하는 문제였다.

 

이같은 문제를 해결하기 위해서는 함수끝에 Close() 를 붙여주면된다.

 

System.IO.File.Create ( string FilePath ).Close() ;

 

System.IO.File.Create ( string FilePath ) 함수는 FileStream 객체를 리턴하게 되는데 위 같이 작성하면 그 객체의 함수를 

호출하게 된다.

 

이 문제에 대한 여러 해결책은 아래 링크를 통해 참조할 수 있다.

http://stackoverflow.com/questions/4680284/system-io-file-create-locking-a-file



출처: https://green4you.tistory.com/23 [Green4You]

 

 

 

 

반응형

 

 

 

728x90

 

 

 

=================================

=================================

=================================

 

 

 

 

출처: https://miss-flower31.tistory.com/entry/C-%ED%8A%B9%EC%A0%95%EA%B2%BD%EB%A1%9C%EC%95%88%EC%97%90-%EC%9E%88%EB%8A%94-%EB%AA%A8%EB%93%A0%ED%8C%8C%EC%9D%BC-%EC%A7%80%EC%9A%B0%EA%B8%B0

 

 

            if (System.IO.Directory.Exists(@"C:\Data"))

            {

                string[] files = System.IO.Directory.GetFiles(@"C:\Data");

                foreach (string s in files)

                {

                    string fileName = System.IO.Path.GetFileName(s);

                    string deletefile = @"C:\Data\" + fileName;

                    System.IO.File.Delete(deletefile);

                    

                }

            }

 

파일경로 적기 귀찮아서 걍 하드코딩함

개별파일만 지울경우에는 

 

System.IO.File.Delete(deletefile); 이것만 써줘도 됨.



출처: https://miss-flower31.tistory.com/entry/C-특정경로안에-있는-모든파일-지우기 [Let me dream.]

 

 

=================================

=================================

=================================

 

 

반응형


관련글 더보기

댓글 영역