Jam*_*mes 1 file-io filesystemobject asp-classic
我试图在用户点击链接删除它时删除图像文件.我没有错误,错误号为零.但是,该文件不会被删除.我可以保存照片文件,但不能因某些原因删除它们.这是我的代码:
PhotoFile = "\images\networkPartners\" & rs(fieldName)
PhotoPath = Server.MapPath(PhotoFile)
dim ServerFSO
Set ServerFSO=Server.CreateObject("Scripting.FileSystemObject")
if ServerFSO.FileExists(PhotoPath) then
response.Write(PhotoPath)
ServerFSO.DeleteFile(PhotoPath)
end if
set ServerFSO=nothing
Run Code Online (Sandbox Code Playgroud)
当response.write命中时,我确实得到了实际的文件路径.("C:/ web/images"等)一直到文件名.所有大写都是正确的等等.再次,当我执行"on next resume next"并写出错误号和字符串时,根本没有错误.
呼叫:
ServerFSO.DeleteFile(PhotoPath, true)
Run Code Online (Sandbox Code Playgroud)
导致错误:
Microsoft VBScript compilation error '800a0414'
Cannot use parentheses when calling a Sub
/folder/file_edit.asp, line 32
ServerFSO.DeleteFile(PhotoPath, true)
-------------------------------------^
Run Code Online (Sandbox Code Playgroud)
检查您的文件是否标有readonly属性.如果是,那么使用
FileSystemObject.DeleteFile filename, true
Run Code Online (Sandbox Code Playgroud)
这将强制删除只读文件.