Unity/코드 예제들

폴더안 파일복사

소나무꼴 2021. 2. 18. 20:43
    void CopyPath(string sourcePath, string destinationPath)
    {
        DirectoryInfo di = new DirectoryInfo(destinationPath);
        if (di.Exists == false)
        {
            di.Create();
        }

        DirectoryInfo diSource = new DirectoryInfo(sourcePath);
        if (diSource.Exists == false)
        {
            Debug.LogError("원본파일이 없습니다");
            return;
        }

        if (System.IO.Directory.Exists(sourcePath))
        {
            string[] files = System.IO.Directory.GetFiles(sourcePath);

            // Copy the files and overwrite destination files if they already exist.
            foreach (string s in files)
            {
                if (s.IndexOf(".meta") >= 0)
                {
                    continue;
                }

                // Use static Path methods to extract only the file name from the path.
                string fileName = System.IO.Path.GetFileName(s);
                string destFile = System.IO.Path.Combine(destinationPath, fileName);
                System.IO.File.Copy(s, destFile, true);
            }
        }
        else
        {
            Debug.LogError("error");
        }
    }