MakeSureDirectoryPathExists和CreateDirectory的区别
2012-08-06 20:32
405 查看
MakeSureDirectoryPathExists和CreateDirectory这两个函数都可以创建目录。
不同点是:MakeSureDirectoryPathExists可以一次性创建深层目录,即多级目录。如:创建C:\dan\shi\ming\目录,只要在本机上存在C盘,就会一次性创建C:\dan和C:\dan\shi和C:\dan\shi\ming这三个目录,但是CreateDirectory不能创建深层目录,比如:要创建C:\dan\shi\ming目录,必须先保证C:\dan和C:\dan\shi目录存在,C:\dan\shi\ming目录才能创建成功;如果C:\dan和C:\dan\shi目录不存在,直接用CreateDirectory创建C:\dan\shi\ming目录不会成功,也不会创建C:\dan和C:\dan\shi目录。因此用CreateDirectory创建深层目录时,必须多次调用CreateDirectory函数且必须保证上层目录创建成功后才创建下级目录。如要创建C:\dan\shi\ming目录,必须按下面那样:
CreateDirectory(_T("C:\\dan")); // 必须先创建C:\dan目录
CreateDirectory(_T("C:\\dan\\shi")); // 然后创建C:\dan\shi目录
CreateDirectory(_T("C:\\dan\\shi\\ming")); // 再创建C:\dan\shi\ming目录
而MakeSureDirectoryPathExists和CreateDirectory(_T("C:\\dan\\shi\\ming")); 一次性就可以成功,即使C:\dan目录和C:\dan\shi目录不存在(不存在时,就会创建不存在的目录)也能创建成功。
不同点是:MakeSureDirectoryPathExists可以一次性创建深层目录,即多级目录。如:创建C:\dan\shi\ming\目录,只要在本机上存在C盘,就会一次性创建C:\dan和C:\dan\shi和C:\dan\shi\ming这三个目录,但是CreateDirectory不能创建深层目录,比如:要创建C:\dan\shi\ming目录,必须先保证C:\dan和C:\dan\shi目录存在,C:\dan\shi\ming目录才能创建成功;如果C:\dan和C:\dan\shi目录不存在,直接用CreateDirectory创建C:\dan\shi\ming目录不会成功,也不会创建C:\dan和C:\dan\shi目录。因此用CreateDirectory创建深层目录时,必须多次调用CreateDirectory函数且必须保证上层目录创建成功后才创建下级目录。如要创建C:\dan\shi\ming目录,必须按下面那样:
CreateDirectory(_T("C:\\dan")); // 必须先创建C:\dan目录
CreateDirectory(_T("C:\\dan\\shi")); // 然后创建C:\dan\shi目录
CreateDirectory(_T("C:\\dan\\shi\\ming")); // 再创建C:\dan\shi\ming目录
而MakeSureDirectoryPathExists和CreateDirectory(_T("C:\\dan\\shi\\ming")); 一次性就可以成功,即使C:\dan目录和C:\dan\shi目录不存在(不存在时,就会创建不存在的目录)也能创建成功。
相关文章推荐
- MakeSureDirectoryPathExists与CreateDirectory的区别
- MakeSureDirectoryPathExists与CreateDirectory的区别
- 2014-03-14周五工作日志:检查指定目录是否存在的函数MakeSureDirectoryPathExists
- 使用 MakeSureDirectoryPathExists 迅速建立多级目录
- 使用 MakeSureDirectoryPathExists 迅速建立多级目录
- windows api一日一练(dbghelp sdk)-002-MakeSureDirectoryPathExists,SearchTreeForFile
- 使用 MakeSureDirectoryPathExists 迅速建立多级目录
- 使用MakeSureDirectoryPathExists 创建多级目录
- VC++ MFC 创建多级目录的方法 MakeSureDirectoryPathExists (另附 文件、目录操作类)
- MakeSureDirectoryPathExists参数不能是正斜杠(“/”)
- MakeSureDirectoryPathExists
- MakeSureDirectoryPathExists检查目录是否存在
- Directory.GetCurrentDirectory和Application.StartupPath的区别
- 解决 `manpath: can't set the locale; make sure $LC_* and $LANG are correct`
- Please make sure you have the correct access rights and the repository exists.解决方法
- The Microsoft Jet database engine could not find the object 'Supports'. Make sure the object exists
- Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "te
- 转载获取路径C#中AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别
- Unable to enable crypto on TCP connection make sure the sslcafile or sslcapath option are properly
- AppDomain.CurrentDomain.BaseDirectory与Application.StartupPath的区别