即在安装目录下如果没有templets文件夹则创建,如果有templets文件夹则将其删除。我先手动建立一个templets文件夹想先看看删除效果。
代码如下:
var tempFile:File
=
File.applicationDirectory.resolvePath("templets");
trace( " tempFile.isDirectory: " + tempFile.isDirectory);
if (tempFile.exists){
// 删除
tempFile.deleteDirectory( true );
} else {
// 创建
tempFile.createDirectory();
}
结果出现如下错误:
trace( " tempFile.isDirectory: " + tempFile.isDirectory);
if (tempFile.exists){
// 删除
tempFile.deleteDirectory( true );
} else {
// 创建
tempFile.createDirectory();
}
SecurityError: fileWriteResource
at runtime::SecurityManager$/checkPrivilegeForCaller()
at flash.filesystem::File/createDirectory()
... ...
哦?,怎么会这样呢。我百思不得其解,然后百度了一下,得到了各位朋友的解决办法
代码如下:
var tempFile:File
=
new
File(File.applicationDirectory.resolvePath(
"
templets
"
).nativePath);
trace( " tempFile.isDirectory: " + tempFile.isDirectory);
trace(tempFile.url);
if (tempFile.exists){
// 删除
tempFile.deleteDirectory( true );
} else {
// 创建
tempFile.createDirectory();
}
trace( " tempFile.isDirectory: " + tempFile.isDirectory);
trace(tempFile.url);
if (tempFile.exists){
// 删除
tempFile.deleteDirectory( true );
} else {
// 创建
tempFile.createDirectory();
}
既然这样可以解决,我就立刻测试,结果我又傻眼了:
出错如下:
Error: Error #2038: File I/O Error.
at flash.filesystem::File/deleteDirectory()
... ...
为什么会这样呢?
奇怪。
我又查了一下,发现别人都是这样做的,为什么我就不行呢。唯一的区别在于别人都是操作文件而我是操作文件夹,难道操作文件夹这种方法不行?
我就不信这个邪,去帮助文档查了一下I/O Error,帮助说目录不存在或无法删除。在 Windows 中无法删除包含已打开文件的目录。
难道我的这个文件夹被其他什么东西给调用着?
我就手动删除这个templets文件夹,结果系统警告说别人在用这个文件夹,不能删除。
原来如此,我的天。
我将这个文件夹和其他程序断开(实际上我是关闭了flash,不知道怎么和flash给连上了),然后再测试就一切正常了。
既可以删除又可以创建。
谢谢百度,谢谢这些朋友,谢谢帮助文档。