---
title: "DirectoryNotFoundException: Could not find a part of the path"
author: "石心.Yong"
published_by: "Perrin Yong"
canonical: https://www.pystone.net/notes/uwa-answer-directory-not-found-exception/
type: note
content_role: source
source_type: "source"
visibility: public
id_stability: rename-stable
source_path: "10-计算机、信息技术与工程/05-游戏图形与运行时/我的UWA问答/2021-05-07 - DirectoryNotFoundException- Could not find a part of the path.md"
content_hash: 4a8ed798cd717ac6f646bd04c784daf1cd3fad1375369911bcf2f22b81efe130
knowledge_version: 224c990773de.5fa8af6e39fa
site_commit: 224c990773de166d23a886306577dd90379529ce
notes_commit: 5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a
---
# DirectoryNotFoundException: Could not find a part of the path

> **note · 我的 UWA 问答**
> 本文收录我在 UWA 问答发表的公开回答。问题内容归原提问者；回答保留当时语境，技术结论可能受 Unity 版本、平台和项目条件限制。

## 问题

Unity2019和2020都有遇到，只是执行文件夹删除再创建，就会报这个错误，大概10次会报1、2次。打log看了是Delete这行报的错，请教大神帮忙解决。

![image.png](/media/b5ee8c3ccd0b94282228.png)

 ![image.png](/media/8c3a0d5111a8254e57bd.png)
 column1
 column2
 column3

 content1
 content2
 content3

- 提问者：路人甲
- 提问时间：2021-05-07 17:38:39

## 我的回答

路径不存在，可能就确实是路径不存在。对Unity Assets下的文件夹，Delete(dir, true)之后，再CreateDirectory大概率是创建失败的。对于文件夹FolderA，Delete会把对应的 FolderA .meta 文件删掉，紧接着，在C#程序创建一个FolderA之后，Unity发现 FolderA .meta 文件被删掉了，会认为你执行了删除FolderA的操作，进而Unity会把刚刚创建的 FolderA再删掉。

可以试一下，对于空文件夹，手动删掉meta文件，在Unity中Refresh之后，Unity会把对应的文件夹删掉。

解决方法如楼上所说，清理文件夹。但是还需要加一个逻辑：保留文件夹的.meta文件。

- 回答时间：2021-05-07 19:25:27
- 最后更新：2021-05-07 19:25:27
- 采纳状态：未采纳

## 来源与关系

- 上位集合：[我的 UWA 问答](https://www.pystone.net/notes/my-uwa-answers/)
- UWA 标签：资源管理、项目管理
- 原始问题：[DirectoryNotFoundException: Could not find a part of the path](https://answer.uwa4d.com/question/60949a1f6bb31032f9791509)
- 源页最后更新：2021-05-07 19:25:27
